473,466 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to translate this vb-code to vb.net

98 New Member
How can I translate this to vb.net?
I have tried a lot, and basicly I'm stuck at passing the txt variable to sendmessage, since this needs to be an intptr apparently..

Expand|Select|Wrap|Line Numbers
  1. Public Function WindowText(window_hwnd As Long) As String
  2. Dim txtlen As Long
  3. Dim txt As String
  4.  
  5.     WindowText = ""
  6.     If window_hwnd = 0 Then Exit Function
  7.  
  8.     txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, 0, 0)
  9.     If txtlen = 0 Then Exit Function
  10.  
  11.     txtlen = txtlen + 1
  12.     txt = Space$(txtlen)
  13.     txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, ByVal txt)
  14.     WindowText = Left$(txt, txtlen)
  15.  
  16.     If WindowText = "MOHAA Console" Then
  17.         WindowText = ""
  18.     ElseIf WindowText = "copy" Then
  19.         WindowText = ""
  20.     ElseIf WindowText = "quit" Then
  21.         WindowText = ""
  22.     ElseIf WindowText = "clear" Then
  23.         WindowText = ""
  24.     End If
  25. findstring$ = WindowText
  26. FindText TargetPosition + 1
  27.  
  28. End Function
  29.  
thanx
May 5 '08 #1
5 1505
Plater
7,872 Recognized Expert Expert
What exactly is that function doing? Maybe there is a completely different way of doing it?
It looks like it is just getting the title of a window from a window handle?
May 5 '08 #2
Gangreen
98 New Member
The function will get text in an other window's textbox using it's windowhandle and put it in a variable...

Public Function WindowText(window_hwnd As Long) As String
Dim txtlen As Long
Dim txt As String

WindowText = ""
'if the given window handle is zero, the function will exit.
If window_hwnd = 0 Then Exit Function

'the length of the text in the windowhandle will be gotten here
txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, 0, 0)
'If the textlength is zero, meaning there is no text, the function exits.
If txtlen = 0 Then Exit Function

txtlen = txtlen + 1
'This declares some kind of buffer for a string I believe...
'I'm not sure since I have never programmed in vb, only in .net

txt = Space$(txtlen)

'This line is what I'm unable to translate. It will get the text in the window
'(which is some kind of multiline textbox) and put it in the txtlen variable.
'Arguments passed to sendmessage: the handle, the command to get text,
'the textlength, and a reference (?) to the buffer. I do not know how to
'pass this last parameter to sendmessage in vb.net

txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, ByVal txt)

'I'm not sure what this does...

WindowText = Left$(txt, txtlen)

'don't mind the rest of the function
If WindowText = "MOHAA Console" Then
WindowText = ""
ElseIf WindowText = "copy" Then
WindowText = ""
ElseIf WindowText = "quit" Then
WindowText = ""
ElseIf WindowText = "clear" Then
WindowText = ""
End If
findstring$ = WindowText
FindText TargetPosition + 1

End Function
May 5 '08 #3
Gangreen
98 New Member
Ok, I figured it out myself, Thanx anyway
May 5 '08 #4
Plater
7,872 Recognized Expert Expert
Did you use:
txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, ByRef txt)
??
I would have passed the variable in by reference and then cast it as an IntPtr. (Note: I don't know if that works, but would be what I tried).

How did you solve it?
May 6 '08 #5
Gangreen
98 New Member
Did you use:
txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, ByRef txt)
??
I would have passed the variable in by reference and then cast it as an IntPtr. (Note: I don't know if that works, but would be what I tried).

How did you solve it?
Dim txt As StringBuilder = New StringBuilder(length)
SendMessage(readbox, WM_GETTEXT, length, txt)

using a stringbuilder as buffer, it did the trick
May 6 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Bengt Richter | last post by:
Just thought None as the first argument would be both handy and mnemonic, signifying no translation, but allowing easy expression of deleting characters, e.g., s = s.translate(None,...
4
by: Zahid | last post by:
Hi, -- URGENT -- I have a short piece of C/C++ code that i need translating into VB.Net. Any volunteers? Know of any websites that do this? Greatly appreciated. code: typedef unsigned...
6
by: Dean Slindee | last post by:
This chunk of code does not translate accurately using the available C# to VB translator tools. I am wondering what the "sub within a sub" structure should look like in VB: starting with the...
3
by: Craig Buchanan | last post by:
if i have a class that is declared public abstract class Hashlist : IDictionary, IEnumerable { ....} how do i translate the following (method?) into vb? IEnumerator...
3
by: Petar Popara | last post by:
Please could someone translate this for me from C/C++ to VB.net? #define MY_CONST 1 typedef struct _MYSTRUCT { const char* p1; int p2; char p3;...
6
by: VBTricks.de.vu Webmaster | last post by:
Hello, in VB6 I used to translate my application by setting the tag-property of all controls, menu-entries... to a number which has been linked to a string (array). Then I went through all...
6
by: Carlos | last post by:
Hi all, ca anybody help me to translate to vb .net this c# instruction? string fname = ((TextBox)GridView1.Rows. Cells.Controls).Text; Thanks, Carlos
3
by: raz230 | last post by:
I'm sorry for posting this here- I have to integrate an parcel tracking with Canada Post into one of my applications. The web service they use is made with SAP and is not the usual WSDL type of...
4
by: kovariadam | last post by:
Hi, Does anybody know why i get this error: SQL0176N The second, third or fourth argument of the TRANSLATE scalar function is incorrect. SQLSTATE=42815 with this query: SELECT...
3
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I've just been tasked to translate a C# project into VB (Dot Net 2.0). I am somewhat familiar with C# but far from an expert. I'd like a second opinion on this one. The project uses CSLA...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.