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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

valuing null hexidecimal value to a variable

Status
Not open for further replies.

mbrown0717

Programmer
Jan 23, 2001
8
US
How do assign a null hexidecimal value to a variable in Visual Basic 6? I want to use that variable to value a certain part of a string using the Mid statement. For example,

myvar = null value
mid(strRecord, 90, 1) = myvar
 
The only variable that can hold a NULL value is a variant. Since a variant is 8 bytes, what you want to do is rather expensive. Perhaps if you could explain why you want to do this, someone could offer a better alternative solution.

Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@earthlink.net
 
The file is an EDI transaction and is generated from other software. When the file was sent to a company we do business with they said that they had a problem with the spaces towards the end of the file. They want nulls after the last tilde (~) to the end of the file. So I created Visual Basic code to go to the end of the file, find the last tilde, determine start and end positions and use the MID statement to write nulls after the tilde to the end. I tested the logic by seeing if I could write anything to that area (i.e., the letter M) and that worked. Then I tried to value the area with nulls and was unsuccessful. How does VB understand null values? I tried to move vbNull, X'00', HEX'00', &H00, etc. to the area and the end result is still spaces.
 
Try vbNullChar which is hex 00, also use the String() function to fill the end of record.



The following is from the VB documentation:

Constant Definition
-------------------------------------------------------------------
vbBack A backspace character [Chr(8)]
vbCr A carriage return [Chr(13)]
vbCrLf A carriage return and line feed [Chr(13) + Chr(10)]
vbLf A linefeed [Chr(10)]
vbNewLine A platform-specific new line character, either
[Chr(13) + Chr(10)] or [Chr(13)]
vbNullChar A null character of value 0 [Chr(0)]
vbNullString A string of value 0 [no Chr code]; note that this is
not the same as ""
vbTab A tab character [Chr(9)]

"Life is full of learning, and then there is wisdom"
 
Why not simply use the replace function

myString = replace(myString, " ", vbnullchar (len(mystring)- instr(1,strReverse(myString),"~") + 1)

This will read the string, find the position of the last ~, by finding the first ~ in the reverse string, and then replace all " " with vbnull values.

As vbnullchar is chr(0) which is hex 00, you can replace this with your chosen value. If your file is writen as a .hex file, you may have to replace the vbnullchar in the above with "00".

Good luck

BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top