|
-
Sep 11th, 2003, 07:29 PM
#1
Thread Starter
yay gay
Help converting small vb6 function to vb.net
help converting vb6 code to .net code(as i am using c# avoid plz putting specific vb words):
VB Code:
Dim lRec As Long
Dim fn As Integer
fn = FreeFile
MsgBox Len(lRec)
Open Left(Drive, 1) & ":\track01.cda" For Random As #fn Len = Len(lRec)
Get #fn, 7, lRec
GetCD_ID1 = Hex$(lRec)
Close fn
i am really needing this function and i dont seem to understand that vb6 commands...could anyone help me with this?
\m/  \m/
-
Sep 11th, 2003, 07:38 PM
#2
Sleep mode
Len = Length in all data type . BTW , what does this function mainly do ?
-
Sep 12th, 2003, 09:27 AM
#3
Thread Starter
yay gay
i think len is self explanatory lol
i want to know get as random , open blablabla
its so small..cant anyone convert it plz?
its to get a cd's id
\m/  \m/
-
Sep 12th, 2003, 09:48 AM
#4
Sleep mode
I changed this code to write in the C drive , and edit the file , it created the file , but didn't write anything inside . At the end of the day what do you want to achieve ?
VB Code:
Private Sub Command1_Click()
Dim lRec As Long
Dim fn As Integer
fn = FreeFile
MsgBox Len(lRec)
Open Left(Drive, 1) & "c:\track01.txt" For Random As #fn Len = Len(lRec)
Get #fn, 7, lRec
GetCD_ID1 = Hex$(lRec)
MsgBox GetCD_ID1
Close fn
End Sub
-
Sep 12th, 2003, 09:56 AM
#5
Thread Starter
yay gay
i dont get what you mean
that code doesnt write anything
it READS
lol
\m/  \m/
-
Sep 12th, 2003, 09:58 AM
#6
Thread Starter
yay gay
how would i convert this to .net?
VB Code:
Open "d:\track01.cda" For Random As #fn Len = 4
Get #fn, 7, lRec
its the only think i need to know......
\m/  \m/
-
Sep 12th, 2003, 10:02 AM
#7
Sleep mode
Originally posted by PT Exorcist
i dont get what you mean
that code doesnt write anything
it READS
lol
but it creates a file
-
Sep 12th, 2003, 10:03 AM
#8
Thread Starter
yay gay
no it doesnt lol
if u have a music cd and use that prog it wont create any kind of file
\m/  \m/
-
Sep 12th, 2003, 10:06 AM
#9
From
VB Code:
Open "d:\track01.cda" For Random As #fn Len = 4
Get #fn, 7, lRec
To
VB Code:
FileOpen(fn, "d:\track01.cda", OpenMode.Random, , , 4)
FileGet(fn, 7, lRec)
-
Sep 12th, 2003, 10:08 AM
#10
Thread Starter
yay gay
Originally posted by Edneeis
From
VB Code:
Open "d:\track01.cda" For Random As #fn Len = 4
Get #fn, 7, lRec
To
VB Code:
FileOpen(fn, "d:\track01.cda", OpenMode.Random, , , 4)
FileGet(fn, 7, lRec)
thanks by converting the code but i dont seem to know FileOpen and FileGet so i think they are in the vb6 compability dll right? could you convert it to real .net functions? (the ones in System.IO because i am using c# and dont want to use the ref to the vb dll)
\m/  \m/
-
Sep 12th, 2003, 10:09 AM
#11
I can't test these but the whole conversion would be somethign like one of these:
VB Code:
Public Function GetCDID(ByVal driveLetter As String) As String
Dim lRec As Long
Dim fn As Integer = FreeFile()
FileOpen(fn, driveLetter.Concat(":\track01.cda"), OpenMode.Random, , , Len(lRec))
FileGet(fn, 7, lRec)
Dim result As String = Hex$(lRec)
FileClose(fn)
Return result
End Function
'or maybe
Public Function GetCDID(ByVal driveLetter As String) As String
Dim lRec As Long
Dim fn As Integer = FreeFile()
FileOpen(fn, driveLetter.Concat(":\track01.cda"), OpenMode.Random, , , Len(lRec))
FileGet(fn, 7, lRec)
FileClose(fn)
Return Hex$(lRec)
End Function
-
Sep 12th, 2003, 10:12 AM
#12
Originally posted by PT Exorcist
thanks by converting the code but i dont seem to know FileOpen and FileGet so i think they are in the vb6 compability dll right? could you convert it to real .net functions? (the ones in System.IO because i am using c# and dont want to use the ref to the vb dll)
Sorry can't help then, at least not without having something to test it on. Its a matter of getting specific bytes in the file after opening it. There are no straight shot conversions of those functions to .NET functions. You'd just have to open the file as a stream and get the bytes you need.
-
Sep 12th, 2003, 10:14 AM
#13
Thread Starter
yay gay
hmm tks by the asnwer
then how should i open the file? as text? as binary stream?
at what point of the file does the code start to read? i didnt get that...at the 4th byte(because FileOpen(fn, "d:\track01.cda", OpenMode.Random, , , 4))..and then the 7 means it reads the next 7 chars? is it it?
\m/  \m/
-
Sep 12th, 2003, 10:18 AM
#14
I'm not exactly sure but you should be able to test it on something and find out. The 4 means go to the 4th record which in this case each record is a long or a byte (i think not sure) but I'm not sure about the 7. You are probably right about reading 7 bytes in.
What should it return? Maybe I have a CD in my car.
-
Sep 12th, 2003, 10:30 AM
#15
Ok this:
VB Code:
'in vb6
Private Sub Command1_Click()
MsgBox GetCD_ID("d")
End Sub
Public Function GetCD_ID(drive As String) As String
Dim lRec As Long
Dim fn As Integer
fn = FreeFile
MsgBox Len(lRec)
Open Left(drive, 1) & ":\track01.cda" For Random As #fn Len = Len(lRec)
Get #fn, 7, lRec
GetCD_ID = Hex$(lRec)
Close fn
End Function
And this
VB Code:
'in vb.NET
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox(GetCDID("d"))
End Sub
Public Function GetCDID(ByVal driveLetter As String) As String
Dim lRec As Long = 7
Dim fn As Integer = FreeFile()
FileOpen(fn, String.Concat(driveLetter, ":\track01.cda"), OpenMode.Random, OpenAccess.Read, , Len(lRec))
FileGet(fn, lRec, 4)
Dim result As String = Hex$(lRec)
FileClose(fn)
Return result
End Function
Both return the samething, which is '3269FCD', whatever that means. Is that what it should do?
Last edited by Edneeis; Sep 12th, 2003 at 10:33 AM.
-
Sep 12th, 2003, 01:32 PM
#16
Thread Starter
yay gay
oh much tks by ur hard work..now ill try out to convert that code to IO classes code..tks a lot
\m/  \m/
-
Sep 13th, 2003, 08:25 AM
#17
I wonder how many charact
All .Net version....
VB Code:
Private Function GetCDID(ByVal driveLetter As String) As String
Dim fs As New IO.FileStream(String.Concat(driveLetter, ":\track01.cda"), IO.FileMode.Open, IO.FileAccess.Read)
Dim c As Int32
Dim g As BitConverter
Dim r(12) As Byte
fs.Read(r, 0, 12)
fs.Close()
'following line starts reading at element 6 in byte array, reads
'in 4 bytes
c = g.ToInt32(r, 6)
System.Windows.Forms.MessageBox.Show(c.ToString)
Return GetCDID = converttoHex(c)
End Function
Private Function converttoHex(ByVal HexValue As Int32) As String
Dim uiDecimal As UInt32
Dim hexstring As String
Try
' Convert text string to unsigned integer
uiDecimal = Convert.ToUInt32(HexValue)
Catch e As System.OverflowException
' Show overflow message and return
Return 0
End Try
' Format unsigned integer value to hex and show in another textbox
hexstring = uiDecimal.ToString("x")
Windows.Forms.MessageBox.Show(hexstring)
Return hexstring
End Function
The C# version I found on the net:
Code:
'tbhex was a textbox
uint uiDecimal = 0;
try
{
// Convert text string to unsigned integer
uiDecimal = checked((uint)System.Convert.ToUInt32(tbDecimal.Text));
}
catch (System.OverflowException exception)
{
// Show overflow message and return
tbHex.Text = "Overflow";
return;
}
// Format unsigned integer value to hex and show in another textbox
tbHex.Text = String.Format("{0:x2}", uiDecimal);
Last edited by nemaroller; Sep 13th, 2003 at 08:34 AM.
-
Sep 13th, 2003, 11:35 AM
#18
Lively Member
Its great and all but what happens when a cd does not have a track01.cda file on it???
Most cd's do but some do not.
and Msg to nemaroller... Excellent code, but in your code the return value = false....
remove the word return and assign the value back to the function.
From
Code:
Return GetCDID = converttoHex(c)
To
Code:
GetCDID = converttoHex(c)
From
To
Code:
converttoHex = hexstring
-
Sep 13th, 2003, 02:17 PM
#19
Thread Starter
yay gay
its for music cds so it will have it
edit: tks all by the code ill check it like in a hour or two because right now im busy
\m/  \m/
-
Sep 13th, 2003, 02:25 PM
#20
Thread Starter
yay gay
hmm sorry to say but actually the code is givin a completly different number than it should be..
with SOAD's toxicity cd the right number is: 1007A9D
and with the .net code im getting: 44430000
:|
\m/  \m/
-
Sep 13th, 2003, 02:27 PM
#21
Thread Starter
yay gay
From
To
Code:
converttoHex = hexstring
[/B][/QUOTE]
and why this?
the right way is Return, the function=value its from the old vb6 if i am not in error and i think its not the best way to do it lol
\m/  \m/
-
Sep 13th, 2003, 05:26 PM
#22
Lively Member
I know that the return is the right way, But with that function it was returning False, so to fix that just return the value to the function solved the problem, I didn't say it was the best method =)
Also the Function returns 44430000 with my Prodigy CD.
Finally NOT all MUSIC CD's have a track01.cda, Put any cd that has Data on it along with music and you will not get a track01.cda.
Do you have Linkin Park's (Meteora) Throw that in and see for yourself.
Thus the function if it worked in the first place would still fail.
-
Sep 13th, 2003, 06:42 PM
#23
I wonder how many charact
Well, I tried converting the C# code that supposedly returns HEX best I could...
I didn't know what to look for as the proper result, and I only had one CD near me at the time.
-
Sep 13th, 2003, 07:13 PM
#24
I wonder how many charact
Anyway, after looking at the original VB6 code again...
its opens the file for random access. The context of which it uses the get statement Get #fn, 7, lrec...
means to grab 4 bytes at byte position 28 (27 in .Net) in the file...?
-
Sep 13th, 2003, 08:10 PM
#25
Thread Starter
yay gay
Originally posted by Evad
I know that the return is the right way, But with that function it was returning False, so to fix that just return the value to the function solved the problem, I didn't say it was the best method =)
Also the Function returns 44430000 with my Prodigy CD.
Finally NOT all MUSIC CD's have a track01.cda, Put any cd that has Data on it along with music and you will not get a track01.cda.
Do you have Linkin Park's (Meteora) Throw that in and see for yourself.
Thus the function if it worked in the first place would still fail.
actually i hate linkin park
\m/  \m/
-
Sep 13th, 2003, 08:14 PM
#26
Lively Member
Prefrence =)...
Hey PT... How did you come along with that Icon Extractor code???
Did it help?
-
Sep 13th, 2003, 08:15 PM
#27
Thread Starter
yay gay
\m/  \m/
-
Sep 13th, 2003, 08:19 PM
#28
Lively Member
THEN CLOSE THE THREAD 
Glad it helped
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|