Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > อยากได้ Function CheckSum Barcode128 C# หรือ VB ก็ได้ครับ....



 

อยากได้ Function CheckSum Barcode128 C# หรือ VB ก็ได้ครับ....

 



Topic : 073100



โพสกระทู้ ( 362 )
บทความ ( 0 )



สถานะออฟไลน์




หาดูมีของ VB ก็ยังงงครับไม่รู้ว่าบางฟังชั่นคืออะไรใน C#
หาของ C# ก็ยังไม่ได้เลย
ถ้ามีเป็น VB ช่วยอธิบายฟังชั่นด้วยครับ



Tag : .NET, Win (Windows App), C#









ประวัติการแก้ไข
2012-02-02 13:11:09
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-02-02 12:50:14 By : hamzter View : 2332 Reply : 7
 

 

No. 1



โพสกระทู้ ( 154 )
บทความ ( 0 )



สถานะออฟไลน์


เว็บนี้อ่านไปยังครับ http://www.mecsw.com/info/appnote/app_004.html

Code (VB.NET)
If Checkdigit = 0 Then
    Checkchar = 174
ElseIf Checkdigit < 94 Then
    Checkchar = Checkdigit + 32
Else
    Checkchar = Checkdigit + 71
End If


ผมว่า code ของเค้าน่าจะผิดนะ ตัว Checkdigit น่าจะเป็นตัวแปรที่ชื่อ CheckSum มากกว่าครับ
ยังไงลองอ่านดูจะได้เข้าใจหลักการก่อนนะครับ เอาไว้เป็นแนวทางได้






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-02 13:20:46 By : gunnermontana
 


 

No. 2



โพสกระทู้ ( 362 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณครับ อันนี้อ่านแล้วครับมันเป็น Access Basic หรือ VB เนี่ยแหละ
ผมไม่รู้ว่าบาง method อย่างเช่น Mid Ascw ไม่รู้ใน C# ใช้อะไรแทนกันอ่ะครับ
ขอบคุณครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-02 13:24:58 By : hamzter
 

 

No. 3



โพสกระทู้ ( 154 )
บทความ ( 0 )



สถานะออฟไลน์


เอา code ตัวอย่างที่หาได้มาให้ผมแปลงเป็น c# ให้ก็ได้ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-02 13:29:03 By : gunnermontana
 


 

No. 4



โพสกระทู้ ( 362 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณครับ
Code (VB.NET)
Function isInt(toCheck As Variant) As Boolean
Dim temp As Integer
On Error GoTo err
temp = CInt(toCheck) 'trys to set the given variable to an integer
isInt = True 'if suceeds then return true
Exit Function
err:
isInt = False 'else return false
End Function

Function Code128b(ByVal rawData) As String
' Function Code128b, returns encoded code128b string (with checkbit)
' default functionality returns string with start and stop bits expected by
' the Code128bWin.ttf font Created by Brian Dobson (http://www.dobsonsw.com)

' provided a 'switch' to allow for apparent characters expected by ID Automations (as well
' as perhaps others') implimentation of Code128B
'
' This function currently has an export limit of 999 characters

    Dim offset, highAscii, total, character, asciivalue, checkdigit
    Dim check, holder, version, startChar, encodeNum, checkCounter
    Dim tstartChar, nstartChar, EndChar, ntChar, tnChar, spaceChar
    Dim encodedString
    Dim previousEncoding ' 0=text 1=numeric
    
    offset = 32
    highAscii = 18
    total = 104 ' initiates checksum total calculator
    
    version = 0  ' set this identifier to '1' for ID automation's version (i hope)
    
    If version = 0 Then ' www.dobsonsw.com's Version
       tstartChar = "š"
       nstartChar = "›"
       EndChar = "œ"
       ntChar = "–"
       tnChar = "•"
       spaceChar = "€"
    ElseIf version = 1 Then 'ID Automation's (and others?) version
       tstartChar = "Ì"
       nstartChar = "Í"
       EndChar = "Î"
       ntChar = "É"
       tnChar = "È" ' I'm guessing at this character, because I have not found an explicit example of this case yet atm
       spaceChar = "€" ' I'm guessing at this character too
    'elseif version = 2 then ' placeholder for 'future' start/stop/seguey characters
       'tstartChar = ""
       'nstartChar = ""
       'EndChar = ""
       'ntChar = ""
       'tnChar = ""
       'spaceChar =""
    End If
      
    For stringCounter = 1 To Len(rawData)
       checkCounter = checkCounter + 1
       'Determine the startCharacter
       If stringCounter = 1 Then
          If isInt(Mid(rawData, stringCounter, 1)) Then
             If isInt(Mid(rawData, stringCounter + 1, 1)) Then
                startChar = nstartChar
                previousEncoding = 1
                total = total + 1
             Else
                startChar = tstartChar
             End If
          Else
             startChar = tstartChar
          End If
       End If
              
       If isInt(Mid(rawData, stringCounter, 1)) Then
          If isInt(Mid(rawData, stringCounter + 1, 1)) Then
             If previousEncoding = 0 Then
                encodedString = encodedString & tnChar
                previousEncoding = 1
                total = total + (((Asc(tnChar) - offset - highAscii)) * checkCounter)
                checkCounter = checkCounter + 1
             End If
             encodeNum = Mid(rawData, stringCounter, 1) & Mid(rawData, stringCounter + 1, 1)
             
             If offset + encodeNum >= 127 Then
                 character = Chr(offset + encodeNum + highAscii)
             Else
                 character = Chr(offset + encodeNum)
             End If
             asciivalue = offset + encodeNum
             stringCounter = stringCounter + 1
             'don't forget to grab the checkbit information for the 'skipped' character
             checkdigit = ((asciivalue - offset) * (checkCounter))
          Else
             If previousEncoding = 1 Then
                encodedString = encodedString & ntChar
                previousEncoding = 0
                total = total + (((Asc(ntChar) - offset - highAscii)) * checkCounter)
                checkCounter = checkCounter + 1
             End If
             character = Mid(rawData, stringCounter, 1)
             asciivalue = Asc(character)
             checkdigit = ((asciivalue - offset) * (checkCounter))
          End If
       Else
          If previousEncoding = 1 Then
             encodedString = encodedString & ntChar
             previousEncoding = 0
             total = total + (((Asc(ntChar) - offset - highAscii)) * checkCounter)
             checkCounter = checkCounter + 1
          End If
          character = Mid(rawData, stringCounter, 1)
          asciivalue = Asc(character)
          checkdigit = ((asciivalue - offset) * (checkCounter))
       End If
          
       ' Replaces any ' ' characters (space) with '€' Characters
       ' I'm not 1000% sure whether this is the character ID Automation's Font uses either...
       If Asc(character) = 32 Then
           character = spaceChar
       End If
       
       encodedString = encodedString & character
       total = total + checkdigit 'adds checkdigit data to running total
    
    Next stringCounter
    
    
   ''' Creates 'checksum character'
    check = total Mod 103
    If (check + offset) >= 127 Then
        holder = check + offset + highAscii
    Else
        holder = check + offset
    End If

    If Chr(holder) <> " " Then
       checkdigit = Chr(holder)
    Else
       checkdigit = spaceChar
    End If
   
    ' Returns barcode string
    Code128b = startChar & encodedString & checkdigit & EndChar
    
End Function

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-02 13:33:04 By : hamzter
 


 

No. 5



โพสกระทู้ ( 362 )
บทความ ( 0 )



สถานะออฟไลน์


แต่รู้สึกอันนี้ http://www.mecsw.com/info/appnote/app_004.html ที่คุณให้มามันก็สั้นดีถ้าอันนี้ได้ก็เอาสั้นๆนี้ดีกว่าครับ ขอบคุณครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-02 13:37:10 By : hamzter
 


 

No. 6



โพสกระทู้ ( 154 )
บทความ ( 0 )



สถานะออฟไลน์


ลองดูก่อนนะครับ

Code (C#)
private string Format_Code128(string InString)
{
    int Sum;
    int Checksum;
    int Checkchar;
    string MyString;
    int CVal;

    //
    //Initialize running total with value of
    //Subset B start character
    //
    Sum = 104;
    //
    //Scan the string and add character value times position
    //
    for (int i = 1; i <= InString.Length; i++)
	{
        //
        // Copy one character from InString position i to MyString
        //
        MyString = InString.Substring(i - 1, 1);
        //
        // Get the numeric value of the character and subtract
        // 32 to shift (the space character, ASCII value 32, has
        // a numeric value of 0 as far as Code 128 is concerned)
        //
        CVal = Convert.ToInt32(Convert.ToChar(MyString)) - 32;
        //
        // Add the weighted value into the running sum
        //
        Sum = Sum + (CVal * i);
	}
    //
    // Calculate the Modulo 103 checksum
    //
    Checksum = Sum % 103;
    //
    // Now convert this number to a character.  This conversion
    // takes into account the particular mapping of the font
    // being used (this example is for the font published by
    // Azalea Software.
    //
    if (Checksum == 0)
    {
        Checkchar = 174;
    }
    else if (Checksum < 94)
    {
        Checkchar = Checksum + 32;
    }
    else
    {
        Checkchar = Checksum + 71;
    }
    //
    // Now format the final output string: start character,
    // data, check character, and stop character
    //
    MyString = Convert.ToChar(162) + InString + Convert.ToChar(Checkchar) + Convert.ToChar(164);
    return MyString;
}

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-02 14:11:10 By : gunnermontana
 


 

No. 7



โพสกระทู้ ( 362 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณมากครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-02 14:16:05 By : hamzter
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : อยากได้ Function CheckSum Barcode128 C# หรือ VB ก็ได้ครับ....
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่