Resolved What is the equivalent code in VB.NET ?

casper

Member
Joined
Jun 6, 2006
Messages
10
Programming Experience
Beginner
Hi There,

I've been trying to convert the below VBA code to VB.NET:

VB.NET:
Option Compare Database

Declare Sub Process Lib "Process.dll" (ByRef sInt As Integer, ByRef sString As MemInfo)

Type MemInfo
    sString As String * 100
End Type

Public Sub test()
    Dim sSize As Integer
    Dim sWord As MemInfo
   
    sSize = 100
    sWord.sString = "Hello: "
    Call Process (sSize , sWord )
   
    MsgBox sWord.sString
    
End Sub

Thanks
 
Last edited by a moderator:
Roughly it's something like this:
VB.NET:
Declare Sub Process Lib "Process.dll" (ByRef sInt As Short, ByRef sString As MemInfo)

Structure MemInfo
    <VBFixedString(100)> Dim sString As String
End Structure

Public Sub test()
    Dim sSize As Integer
    Dim sWord As MemInfo
   
    sSize = 100
    sWord.sString = "Hello: "
    Call Process (sSize , sWord)
   
    Messagebox.Show(sWord.sString)
    
End Sub
Don't expect this to work 100% right off the bat, I converted it using notepad.
 
hey mate.. i'm having this error while running in .NET:

attempt to read or write protected memory. this is often an indication that other memory is corrupt

I've tested VBA code and working perfectly..

any thoughts?
 
What line is it erroring on and what's the exact error message? (Posting a screenshot of the error message should be good enough)
 
attached is the file
 

Attachments

  • error.JPG
    error.JPG
    57.3 KB · Views: 26
Visual Studio 2005 converted it to this:

VB.NET:
	Declare Sub Process Lib "Process.dll" (ByRef sInt As Short, ByRef sString As MemInfo)

	Structure MemInfo
		<VBFixedString(100), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=100)> Public sString() As Char
	End Structure

	Public Sub test()
		Dim sSize As Short
		Dim sWord As MemInfo

		sSize = 100
		sWord.sString = "Hello: "
		Call Process(sSize, sWord)

		MsgBox(sWord.sString)

	End Sub
 
Hey mate the following error has occurred.

P.S: the VBA code is working correctly. I just don't understand why the memory allocation is different between VBA and .NET! any further thoughts?

thanks
 

Attachments

  • error.JPG
    error.JPG
    51.5 KB · Views: 29
hey mate.. i got it working...

changed the following code:
VB.NET:
Structure Meminfo
        <VBFixedString(100), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=100)> Dim sCobol As String
    End Structure

to:

VB.NET:
Structure Meminfo
        <VBFixedString(100), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=100)> Dim sCobol As String
    End Structure

MANY THANKS FOR YOUR HELP.. REALLY REALLY REALLY APPRECIATED!!!! :)
 
Back
Top