Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use Split function with Unicode Delimiter in Visual Basic 6

Status
Not open for further replies.

NewAccount13

Systems Engineer
Jul 19, 2022
4
BG
Hello everyone, i am facing some issue with unique delimiter in visual basic 6. I am trying to create security application which is compatible with Chinese Windows. Although i did many tests today, its still doesn't work. It works only on English Windows.I am pasting the code, and if someone have any idea, i would be grateful for the guidance.
P.s so far, i understood that i need to use ChrW , but as i said, it still doesn't work.
That's not the whole code, just the part that i need to be converted to works on Chinese and other Languages.

The problem are 2 from what i see, the first the split function, how to convert to Unicode, and second does the String must be converted fromUnicode?
on this line - test YO, StrConv(sData(1), vbFromUnicode)


Sub Main()


Dim YO As String, Datos As String, sData() As String

YO = App.Path & "\" & App.EXEName & ".exe"

Open YO For Binary As #1
Datos = Space(LOF(1))
Get #1, , Datos
Close #1

sData() = Split(Datos, "DELIMITER1")

sData(1) = TEST2(sData(1), "TEST")

test YO, StrConv(sData(1), vbFromUnicode)
End
 
I dont know the delimiter is a problem for chinese windows etc....
 
Firstly I'd try

sData() = Split(Datos, StrConv("while", vbUnicode))

but I'd suggest that what you are trying to do here is at best likely to be flakey ...
 
Because

1) An EXE file is not a text file (whether ANSI or Unicode 16), and simply trying to treat it as great big string buffer will lead to heartache
2) VB6 isn't great with Unicode, and is essentially works in ANSI (yes, the internal representation of strings is Unicode 16, but VB does it's level best to keep this hidden from you and jumps through hoops to translate to and from the internal Unicode representation. Those hoops assume certain things about the string buffer which may not be true if the buffer is actually the contents of an exe file. The following may illustrate:

Code:
[COLOR=blue]    Dim fred1() As Byte
    Dim fred2() As Byte
    Dim fred3() As Byte
    
    Dim stringy As String
    Dim stringy2 As String
    
    stringy = ChrW(65) & ChrW(66) & ChrW(67)   [COLOR=green]' explicitly create genuine unicode 16 LE string "ABC"[/color]
    stringy2 = ChrB(66) & stringy [COLOR=green]' add a byte before the unicode string,  a simplified version of what an exe file might do ...[/color]
    
    fred1 = stringy [COLOR=green]' stick clean unicode string in a byte array so we can examoine it[/color]
    
    fred2 = Split(stringy, "B")(0)  [COLOR=green]' split our clean unicode string - works[/color]
    fred3 = Split(stringy2, "B")(0) [COLOR=green]' split our 'exe file' version - does not work[/color]
    Stop [COLOR=green]' examine contents of fred1, fred2 and fred3 in Locals in IDE[/color][/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top