Now i know there are fair few threads here, about this subject but ive tried a few things & still getting issues
the program creates a MAC Address & then saves in binary to a file, It works perfectly, But i also want to convert this btye array to a string & save to a textfile So we then can read it in notepad
however as you can see ive tried & the String Comes out as ??00 & not somthing like 7E:74 etc.
Could you help on where i went wrong?
the program creates a MAC Address & then saves in binary to a file, It works perfectly, But i also want to convert this btye array to a string & save to a textfile So we then can read it in notepad
however as you can see ive tried & the String Comes out as ??00 & not somthing like 7E:74 etc.
Could you help on where i went wrong?
Code:
Dim MACBytAr(5) As Byte
Dim MACP_LN As Byte
Dim MACP_UN As Byte
Dim i, j As Integer
Dim filenum As Integer
Dim sAns As String
Dim iPos As String
Dim ByteArrayToString As String
i = 0
' START OF CODE
'// Initializes the random-number generator, otherwise each time you run your
For j = 0 To 5
Randomize
MACP_LN = Int((15 - 0 + 1) * Rnd() + 0) ' Generate random value between 0 and 15 for the Lower Nibble.
Randomize
MACP_UN = Int((15 - 0 + 1) * Rnd() + 0) ' Generate random value between 0 and 15 for the Upper Nibble .
MACP_UN = MACP_UN * 16
MACBytAr(i) = (MACP_UN + MACP_LN)
i = i + 1
Next j
MAC1 = Val(MACBytAr(0)) & ":" & Val(MACBytAr(1)) & ":" & Val(MACBytAr(2)) & ":" & Val(MACBytAr(3)) & ":" & Val(MACBytAr(4)) & ":" & Val(MACBytAr(5))
filenum = FreeFile()
Open "location" For Binary As #filenum
Put #filenum, , MACBytAr
Close #filenum
sAns = StrConv(MACBytAr, vbFromUnicode)
iPos = InStr(sAns, Chr(0))
If iPos > 0 Then sAns = Left(sAns, iPos - 1)
ByteArrayToString = sAns
Label1 = ByteArrayToString
Open "location" For Append As #filenum
Print #filenum, , ByteArrayToString
Close #filenum