Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
The subject of my post is pretty much my question. In vb6 is "file" different in any way from the vb.net "GetFile"?

Also Form_Load event was upgraded to Form_Load method. Any difference there?

Thank you!

*** UPDATE ***

To put it another way, here is code that is vb6 that I want to convert to vb.net:

VB
Private Sub Command1_Click(ByVal eventSender As Object, ByVal eventArgs As EventArgs) Handles Command1.Click
       Dim u As Object
       cd1Open.ShowDialog()
       If Strings.Len(cd1Open.FileName) = 0 Then Exit Sub
       FileSystem.FileOpen(1, cd1Open.FileName, OpenMode.Binary)
       ReDim FDATA(FileSystem.LOF(1) - 1)
       'UPGRADE_WARNING: (2080) Get was upgraded to FileGet and has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2080.aspx
       FileSystem.FileGet(1, FDATA, -1)
       FileSystem.FileClose(1)

       If ReadPE(FDATA) = 0 Then
           MessageBox.Show("File is not Win32 Executeable!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error) : Exit Sub
       End If
'UPGRADE_WARNING: (2080) Form_Load event was upgraded to Form_Load method and has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2080.aspx
  Private Sub Form_Load()
      Top = (Screen.PrimaryScreen.Bounds.Height - Height) / 2
      Left = (Screen.PrimaryScreen.Bounds.Width - Width) / 2
  End Sub

Also, I am having problems with this bit of code...
VB
Public Function ReadPE(ByRef DATA() As Byte) As Byte
            On Error GoTo ErrX
            Dim CNT As Integer
            'UPGRADE_WARNING: (2081) Len has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2081.aspx
            UpgradeSolution1Support.SafeNative.kernel32.CopyMemory(DOSHEADER, DATA(CNT), CShort(Marshal.SizeOf(DOSHEADER)))
            If DOSHEADER.e_magic.Value <> "MZ" Then Exit Function
            'UPGRADE_WARNING: (2081) Len has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2081.aspx
            UpgradeSolution1Support.SafeNative.kernel32.CopyMemory(NTHEADER, DATA(DOSHEADER.e_lfanew), CShort(Marshal.SizeOf(NTHEADER)))
            'UPGRADE_WARNING: (2081) Len has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2081.aspx
            CNT = CNT + DOSHEADER.e_lfanew + Marshal.SizeOf(NTHEADER)
            If NTHEADER.Signature.Value <> "PE" & Strings.Chr(0).ToString() & Strings.Chr(0).ToString() Then Exit Function
            ReDim SECTIONSHEADER(NTHEADER.FileHeader.NumberOfSections - 1)
            For Each SECTIONSHEADER_item As IMAGE_SECTION_HEADER In SECTIONSHEADER
                'UPGRADE_WARNING: (2081) Len has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2081.aspx
                'UpgradeSolution1Support.SafeNative.kernel32.CopyMemory(SECTIONSHEADER_item, DATA(CNT), CShort(Marshal.SizeOf(SECTIONSHEADER(0))))
                'UPGRADE_WARNING: (2081) Len has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2081.aspx
                CNT += Marshal.SizeOf(SECTIONSHEADER(0))
            Next SECTIONSHEADER_item
            Return 1
ErrX:
            On Error GoTo 0
        End Function

Any suggestion will be greatly appreciated as how to convert this to vb.net.

[Edit - added code from comments]
Posted
Updated 23-Apr-12 11:09am
v3
Comments
Richard MacCutchan 22-Apr-12 10:35am    
Did you check the MSDN documentation for these two functions?
Dale 2012 22-Apr-12 10:59am    
yes.... I understand that "file" is used when you want to copy, move or delete a file and getfile Returns a File Object corresponding to the file in a specified path. My question was will the upgraded "getFile" still act in the same mannor?
Sergey Alexandrovich Kryukov 22-Apr-12 14:55pm    
I cannot see any sense in "Form_Load event was upgraded to Form_Load method". Could you explain what does it mean? How one can be "ungraded with another"? For your information, there is no such event as "Form_Load", the event is Form.Load. Could you make a code sample, really small but comprehensive?
--SA
Dale 2012 22-Apr-12 18:42pm    
<pre lang="vb">Private Sub Command1_Click(ByVal eventSender As Object, ByVal eventArgs As EventArgs) Handles Command1.Click
Dim u As Object
cd1Open.ShowDialog()
If Strings.Len(cd1Open.FileName) = 0 Then Exit Sub
FileSystem.FileOpen(1, cd1Open.FileName, OpenMode.Binary)
ReDim FDATA(FileSystem.LOF(1) - 1)
'UPGRADE_WARNING: (2080) Get was upgraded to FileGet and has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2080.aspx
FileSystem.FileGet(1, FDATA, -1)
FileSystem.FileClose(1)

If ReadPE(FDATA) = 0 Then
MessageBox.Show("File is not Win32 Executeable!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error) : Exit Sub
End If</pre>

<pre lang="vb">'UPGRADE_WARNING: (2080) Form_Load event was upgraded to Form_Load method and has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2080.aspx
Private Sub Form_Load()
Top = (Screen.PrimaryScreen.Bounds.Height - Height) / 2
Left = (Screen.PrimaryScreen.Bounds.Width - Width) / 2
End Sub</pre>




Also I am having problems with this bit of code..
<pre lang="vb">Public Function ReadPE(ByRef DATA() As Byte) As Byte
On Error GoTo ErrX
Dim CNT As Integer
'UPGRADE_WARNING: (2081) Len has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2081.aspx
UpgradeSolution1Support.SafeNative.kernel32.CopyMemory(DOSHEADER, DATA(CNT), CShort(Marshal.SizeOf(DOSHEADER)))
If DOSHEADER.e_magic.Value <> "MZ" Then Exit Function
'UPGRADE_WARNING: (2081) Len has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2081.aspx
UpgradeSolution1Support.SafeNative.kernel32.CopyMemory(NTHEADER, DATA(DOSHEADER.e_lfanew), CShort(Marshal.SizeOf(NTHEADER)))
'UPGRADE_WARNING: (2081) Len has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2081.aspx
CNT = CNT + DOSHEADER.e_lfanew + Marshal.SizeOf(NTHEADER)
If NTHEADER.Signature.Value <> "PE" & Strings.Chr(0).ToString() & Strings.Chr(0).ToString() Then Exit Function
ReDim SECTIONSHEADER(NTHEADER.FileHeader.NumberOfSections - 1)
For Each SECTIONSHEADER_item As IMAGE_SECTION_HEADER In SECTIONSHEADER
'UPGRADE_WARNING: (2081) Len has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2081.aspx
'UpgradeSolution1Support.SafeNative.kernel32.CopyMemory(SECTIONSHEADER_item, DATA(CNT), CShort(Marshal.SizeOf(SECTIONSHEADER(0))))
'UPGRADE_WARNING: (2081) Len has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2081.aspx
CNT += Marshal.SizeOf(SECTIONSHEADER(0))
Next SECTIONSHEADER_item
Return 1
ErrX:
On Error GoTo 0
End Function



any suggestion will be great as how to convert this to vb.net
Kschuler 23-Apr-12 17:10pm    
I copied this code into your original question. Next time instead of replying to a comment with more info like that, click the Improve Question button and add it there. Code can be formatted and it's easier for people reading the question to get all the info instead of having to read all the comments.

1 solution

From everything that has been posted, you took a VB6 chunk of junk, ran it through the VB.NET converter thinking that it would give you great code that will run out of the box.

Unfortunately every conversion warning you received is no different than a compiler warning. It is something you darn well better look into. Especially when your warnings tell you 'and has a new behavior.'

This is absolutely no different than if you get a compiler warning that the code is obsolete and it recommends you use something else. You have to study each message and read the links and then plan on rewriting your code to fit into the .net framework.

I'd especially plan on getting rid of that ON ERROR GOTO crap that should never exist in any .NET code, and all of the MemCopy code that is called directly into the Kernel.
 
Share this answer
 
Comments
Dale 2012 3-May-12 22:15pm    
ok what suggestions can you make about the copy memory crap? I am unsure of how or where to find examples that use this method

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900