Visual Basic .NET Forums  

Go Back   Visual Basic .NET Forums > VB.NET > VB.NET General Discussion

VB.NET General Discussion VB.NET general discussion area

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-04-2008, 11:39 PM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Jun 2006
Posts: 10
Reputation: 40
casper is on a distinguished programming path ahead
Default What is the equivalent code in VB.NET ?

Hi There,

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

Code:
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 JuggaloBrotha; 12-09-2008 at 8:34 AM. Reason: Set to resolved based on last OP post
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-05-2008, 8:56 AM
JuggaloBrotha's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jun 2004
Location: Lansing, MI; USA
Age: 25
Posts: 3,278
Reputation: 259
JuggaloBrotha puts e.f. hutton to shameJuggaloBrotha puts e.f. hutton to shameJuggaloBrotha puts e.f. hutton to shameJuggaloBrotha puts e.f. hutton to shameJuggaloBrotha puts e.f. hutton to shameJuggaloBrotha puts e.f. hutton to shame
Default

Roughly it's something like this:
Code:
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.
__________________

There are 3 kinds of people in the world: Those who can count and those who can't.
4 out of 3 people have trouble with fractions.

Windows has a 64 bit GUI for a set of 32 bit extensions on a 16 bit shell for an 8 bit OS using a 4 bit kernel made by a 2 bit company that can't stand 1 bit of competition.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-07-2008, 10:23 PM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Jun 2006
Posts: 10
Reputation: 40
casper is on a distinguished programming path ahead
Default

hey mate.. i'm having this error while running in .NET:

Quote:
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-08-2008, 9:02 AM
JuggaloBrotha's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jun 2004
Location: Lansing, MI; USA
Age: 25
Posts: 3,278
Reputation: 259
JuggaloBrotha puts e.f. hutton to shameJuggaloBrotha puts e.f. hutton to shameJuggaloBrotha puts e.f. hutton to shameJuggaloBrotha puts e.f. hutton to shameJuggaloBrotha puts e.f. hutton to shameJuggaloBrotha puts e.f. hutton to shame
Default

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

There are 3 kinds of people in the world: Those who can count and those who can't.
4 out of 3 people have trouble with fractions.

Windows has a 64 bit GUI for a set of 32 bit extensions on a 16 bit shell for an 8 bit OS using a 4 bit kernel made by a 2 bit company that can't stand 1 bit of competition.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12-08-2008, 4:51 PM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Jun 2006
Posts: 10
Reputation: 40
casper is on a distinguished programming path ahead
Default

attached is the file
Attached Images
File Type: jpg error.JPG (57.3 KB, 10 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 12-08-2008, 4:55 PM
VB.NET Forum Idol
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Posts: 712
Reputation: 369
MattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalistMattP VB.NET gold medalist
Default

Visual Studio 2005 converted it to this:

Code:
	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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 12-08-2008, 5:05 PM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Jun 2006
Posts: 10
Reputation: 40
casper is on a distinguished programming path ahead
Default

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
Attached Images
File Type: jpg error.JPG (51.5 KB, 11 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 12-08-2008, 5:21 PM
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Jun 2006
Posts: 10
Reputation: 40
casper is on a distinguished programming path ahead
Default

hey mate.. i got it working...

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

Code:
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!!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 9:30 PM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0


For advertising opportunities click here.