Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1016
  • Last Modified:

VB to VB.Net upgrade errors. help

Can anyone please help me with the solution for the question at the following URL

http://dbforums.com/arch/26/2002/7/444205

Added to that I have some "Return"  keywords in my VB program which Vb.Net upgrade wizard gives an error. How to resolve that error.

I am facing with the same kind of problems metioned there

Thanks in advance
0
ramesh12
Asked:
ramesh12
  • 9
  • 4
1 Solution
 
Mikal613Commented:
Every function myst have a return statement
0
 
ramesh12Author Commented:
When I have upgraded my vb6 program VB.Net shows something like this

            lbldisplay(LabelNum_int_g).Text = Dsp_stg
            lbldisplay(LabelNum_int_g).Visible = True
            LabelNum_int_g = LabelNum_int_g + 1
            'UPGRADE_WARNING: Return has a new behavior. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1041"'
            Return



and my original vb code is something like this

  lbldisplay(LabelNum_int_g).Caption = Dsp_stg
  lbldisplay(LabelNum_int_g).Visible = True
  LabelNum_int_g = LabelNum_int_g + 1

  Return


Problem is not with the returning of values from a function. For now I just commented out return to see what happens . BUt my main problem is with converting "AS ANY" to proper type. How do I change that.

Thank you
0
 
Mikal613Commented:
do as Object instead
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Mikal613Commented:
post your Full Function you have the problem with
0
 
Mikal613Commented:
as any and variant are no longer supported and replaced as Object
0
 
Mikal613Commented:
There are three cases where you may need to make some changes. The first is passing user-defined types that contain fixed-length strings or byte arrays to APIs. In Visual Basic .NET you may need to change your code, adding the MarshallAs attribute (from System.Runtime.InteropServices) to each fixed-length string or byte array in the user-defined type. The second case is using the As Any variable type in a Declare statement. This is not supported in Visual Basic .NET. Variables of type As Any were often used to pass a variable that was either a string or Null; you can replace this Visual Basic 6.0 usage by declaring two forms of the API, one with longs, one with strings. For example, the GetPrivateProfileString API has a parameter lpKeyName of type As Any:

0
 
ramesh12Author Commented:
I have something like this in VB

Declare Sub hMemCpy Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any, Source As Any, ByVal Copy As Long)


and that is converted like this

      'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1016"'
      'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1016"'
    Declare Sub hMemCpy Lib "kernel32" Alias "RtlMoveMemory" (ByRef Dest As Any, ByRef Source As Any, ByVal Copy As Integer)



In VB I am using calls like this

  Dim MinorWindowsVersion_Byte    As Byte
  Dim MajorWindowsVersion_Byte    As Byte

  Dim WordStuct     As DoubleWord
  Dim ByteStruct    As DoubleByte


'retrieve version via API call & copy into double-word structure
 
  Call hMemCpy(WordStuct, GetVersion(), Len(WordStuct))

'copy low word into double byte structure
  Call hMemCpy(ByteStruct, WordStuct.LowWord, Len(ByteStruct))


and this is converted to

            Dim MinorWindowsVersion_Byte As Byte
            Dim MajorWindowsVersion_Byte As Byte
            
            Dim WordStuct As DoubleWord
            Dim ByteStruct As DoubleByte
            
            
            'retrieve version via API call & copy into double-word structure
            
            'UPGRADE_WARNING: Couldn't resolve default property of object WordStuct. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
            Call hMemCpy(WordStuct, GetVersion(), Len(WordStuct))
            
            'copy low word into double byte structure
            'UPGRADE_WARNING: Couldn't resolve default property of object ByteStruct. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
        Call hMemCpy(ByteStruct, WordStuct.LowWord, Len(ByteStruct))
            

What should I do with ANY now. Actually the documentation says it takes pointers to the source and destination .Here is the URL

http://msdn.microsoft.com/library/en-us/memory/base/copymemory.asp?frame=true
0
 
Mikal613Commented:
Declare Sub hMemCpy Lib "kernel32" Alias "RtlMoveMemory" (Dest As String, Source As Any, ByVal Copy As Long)


0
 
Mikal613Commented:
it says to change the As Any to String or long Dest seems to be a string
0
 
ramesh12Author Commented:
Thanks Mikal
                   I removed entirely hMemCpy from my program and made some changes, and my program is returning the results that I want.

But basically that particular hMemCopy is being used to check for the OS version. Here is the code

Declare Function GetVersion Lib "kernel32" () As Long

Private Function ValidWindowsVersion_bool() As Boolean

  Dim MinorWindowsVersion_Byte    As Byte
  Dim MajorWindowsVersion_Byte    As Byte

  Dim WordStuct     As DoubleWord
  Dim ByteStruct    As DoubleByte


'retrieve version via API call & copy into double-word structure
 
  Call hMemCpy(WordStuct, GetVersion(), Len(WordStuct))

'copy low word into double byte structure
  Call hMemCpy(ByteStruct, WordStuct.LowWord, Len(ByteStruct))

'set version
  MinorWindowsVersion_Byte = ByteStruct.LowByte
  MajorWindowsVersion_Byte = ByteStruct.HighByte


'set whether this is a valid version
  If MajorWindowsVersion_Byte >= 4 Then
'it's at least Windows 4.0 (Windows 95)
    ValidWindowsVersion_bool = True
  Else
    ValidWindowsVersion_bool = False
  End If

End Function

So I have removed this . Now Is there any easy way in .net to check this

0
 
ramesh12Author Commented:
I think I have got everything set. I really appreciate your help Mikal.

Thank you
0
 
Mikal613Commented:
Public Function OS_Version() As String

        Dim osInfo As OperatingSystem
        Dim sAns As String

        osInfo = System.Environment.OSVersion

        With osInfo
            Select Case .Platform
                Case .Platform.Win32Windows
                    Select Case (.Version.Minor)
                        Case 0
                            sAns = "Windows 95"
                        Case 10
                            If .Version.Revision.ToString() = "2222A" Then
                                sAns = "Windows 98 Second Edition"
                            Else
                                sAns = "Windows 98"
                            End If
                        Case 90
                            sAns = "Windows Me"
                    End Select
                Case .Platform.Win32NT
                    Select Case (.Version.Major)
                        Case 3
                            sAns = "Windows NT 3.51"
                        Case 4
                            sAns = "Windows NT 4.0"
                        Case 5
                            If .Version.Minor = 0 Then
                                sAns = "Windows 2000"
                            ElseIf .Version.Minor = 1 Then
                                sAns = "Windows XP"
                            ElseIf .Version.Minor = 2 Then
                                sAns = "Windows Server 2003"
                            Else 'Future version maybe update
                                 'as needed
                                sAns = "Unknown Windows Version"
                            End If
                    End Select

            End Select
        End With

        Return sAns
    End Function
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 9
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now