Solved

VB to VB.Net upgrade errors. help

Posted on 2004-03-31
13
997 Views
Last Modified: 2007-12-19
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
Comment
Question by:ramesh12
  • 9
  • 4
13 Comments
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
Every function myst have a return statement
0
 
LVL 7

Author Comment

by:ramesh12
Comment Utility
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
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
do as Object instead
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
post your Full Function you have the problem with
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
as any and variant are no longer supported and replaced as Object
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 500 total points
Comment Utility
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
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
 
LVL 7

Author Comment

by:ramesh12
Comment Utility
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
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
Declare Sub hMemCpy Lib "kernel32" Alias "RtlMoveMemory" (Dest As String, Source As Any, ByVal Copy As Long)


0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
it says to change the As Any to String or long Dest seems to be a string
0
 
LVL 7

Author Comment

by:ramesh12
Comment Utility
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
 
LVL 7

Author Comment

by:ramesh12
Comment Utility
I think I have got everything set. I really appreciate your help Mikal.

Thank you
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now