dobe
Feb 6th, 2002, 09:26 AM
Hello Fellow Early-Adopters!
I don't know where to ask VB.NET questions apparently, to get any answers, so I'm
trying this one and may cross-post until someone either answers or complains! (I also sent
email to "Ask Dr.NET" but have not had one reply from anywhere!)
I have three questions on VB.NET coding:
The first is that VB.NET does not seem to have an easy way (as VB6 did) to stick a
(User-chosen) complete Directory Path (not just the filename, which could be chosen easily
enough with the tools available) but ONLY a directory, (as in a starting point to do a "Dir"
command from), into a variable or say, a textbox.
I know I can use the VB6 controls, and used a simple form with the old DriveListBox,
DirListBox and a textbox which in VB6 works very well. It actually works in VB.NET, also, but
the problem is and the User must double-click about 3 times on a chosen directory to actually
get the name of the Drive:\Directory to appear in the textbox...
While this might be marginally acceptable, the behavior is radically different from
VB6, and I could not find a comparable way to do this with the new VB.NET controls at all.
There probably is a way to do it with the new controls, but I have attempted to do
this for many days in many ways and was never successful.
The second problem I have come up against is that in VB6, it was possible to define
the event code for say a menu item like this:
Private Sub mnuFileExit_Click()
Unload Me
End Sub
OK, now elsewhere in the program you could simply call:
mnuFileExit_Click
from a command button, say, and it would use the previously defined code.
Now, it seems, VB.NET wants us to connect "Multiple Events to a Single Event Handler",
like so:
' Visual Basic.NET
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click, Button2.Click
'Add Event Handler Code Here
End Sub
but this is NOT really the same! While this is great, suppose I really DO want to simulate the
event in code elsewhere, in a function, let's say. I can find no way to do this, since I
cannot simply call
Button1_Click
and have it use the previously defined code! It stops compiling since I cannot supply the
(ByVal sender As System.Object,ByVal e As System.EventArgs)
params from code elsewhere *programmatically*. There may be a way, but
I could not discover it by experimentation nor Help files...
The third problem I have is while trying to use a RichTextBox control to *FIND* a
string, I can:
myValue = InputBox(message, title, defaultValue)
' set Global gStrValue for next search...
gStrValue = myValue
FindMyText(myValue)
then use a function like (right out of the Help file):
Public Function FindMyText(ByVal text As String) As Boolean
' Initialize the return value to false by default.
Dim returnValue As Boolean = False
' Ensure a search string has been specified.
If text.Length > 0 Then
' Obtain the location of the search string in richTextBox1.
Dim indexToText As Integer = rtbEdit.Find(text)
' Determine whether the text was found in richTextBox1.
If indexToText >= 0 Then
returnValue = True
End If
End If
Return returnValue
End Function
Fine. It goes to the first instance, but then will never find a second instance. So in
the Help files, it says to overload the Function with a position (start) like so (again,
straight out of the Help files):
Public Function FindMyText(ByVal text As String, _
ByVal start As Integer) As Integer
' Initialize the return value to false by default.
Dim returnValue As Integer = -1
' Ensure search string specified with valid start point.
If text.Length > 0 And start >= 0 Then
' Obtain the location of the search string in richTextBox1.
Dim indexToText As Integer = richTextBox1.Find _
(text, start, RichTextBoxFinds.MatchCase)
' Determine whether the text was found in richTextBox1.
If indexToText >= 0 Then
returnValue = indexToText
End If
End If
Return returnValue
End Function
So I would like to have this set up where I call the next (overloaded) FIND with the
shortcut <F3>, but I cannot seem to be able to programmatically determine what *integer* to
plug in as the "start"
parameter. So it fails, unless I put in a hardcoded "0", for instance,
and then it will again find the first instance... I know this is wrong, but I'm stuck as to
how to send the correct location of the cursor in the RTB control during run mode...
Thanks in advance,
Dobe <dobe@eskimo.com>
PS: I could send complete ZIP'ped examples to anyone willing to take a look at this, if that
would help...
I don't know where to ask VB.NET questions apparently, to get any answers, so I'm
trying this one and may cross-post until someone either answers or complains! (I also sent
email to "Ask Dr.NET" but have not had one reply from anywhere!)
I have three questions on VB.NET coding:
The first is that VB.NET does not seem to have an easy way (as VB6 did) to stick a
(User-chosen) complete Directory Path (not just the filename, which could be chosen easily
enough with the tools available) but ONLY a directory, (as in a starting point to do a "Dir"
command from), into a variable or say, a textbox.
I know I can use the VB6 controls, and used a simple form with the old DriveListBox,
DirListBox and a textbox which in VB6 works very well. It actually works in VB.NET, also, but
the problem is and the User must double-click about 3 times on a chosen directory to actually
get the name of the Drive:\Directory to appear in the textbox...
While this might be marginally acceptable, the behavior is radically different from
VB6, and I could not find a comparable way to do this with the new VB.NET controls at all.
There probably is a way to do it with the new controls, but I have attempted to do
this for many days in many ways and was never successful.
The second problem I have come up against is that in VB6, it was possible to define
the event code for say a menu item like this:
Private Sub mnuFileExit_Click()
Unload Me
End Sub
OK, now elsewhere in the program you could simply call:
mnuFileExit_Click
from a command button, say, and it would use the previously defined code.
Now, it seems, VB.NET wants us to connect "Multiple Events to a Single Event Handler",
like so:
' Visual Basic.NET
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click, Button2.Click
'Add Event Handler Code Here
End Sub
but this is NOT really the same! While this is great, suppose I really DO want to simulate the
event in code elsewhere, in a function, let's say. I can find no way to do this, since I
cannot simply call
Button1_Click
and have it use the previously defined code! It stops compiling since I cannot supply the
(ByVal sender As System.Object,ByVal e As System.EventArgs)
params from code elsewhere *programmatically*. There may be a way, but
I could not discover it by experimentation nor Help files...
The third problem I have is while trying to use a RichTextBox control to *FIND* a
string, I can:
myValue = InputBox(message, title, defaultValue)
' set Global gStrValue for next search...
gStrValue = myValue
FindMyText(myValue)
then use a function like (right out of the Help file):
Public Function FindMyText(ByVal text As String) As Boolean
' Initialize the return value to false by default.
Dim returnValue As Boolean = False
' Ensure a search string has been specified.
If text.Length > 0 Then
' Obtain the location of the search string in richTextBox1.
Dim indexToText As Integer = rtbEdit.Find(text)
' Determine whether the text was found in richTextBox1.
If indexToText >= 0 Then
returnValue = True
End If
End If
Return returnValue
End Function
Fine. It goes to the first instance, but then will never find a second instance. So in
the Help files, it says to overload the Function with a position (start) like so (again,
straight out of the Help files):
Public Function FindMyText(ByVal text As String, _
ByVal start As Integer) As Integer
' Initialize the return value to false by default.
Dim returnValue As Integer = -1
' Ensure search string specified with valid start point.
If text.Length > 0 And start >= 0 Then
' Obtain the location of the search string in richTextBox1.
Dim indexToText As Integer = richTextBox1.Find _
(text, start, RichTextBoxFinds.MatchCase)
' Determine whether the text was found in richTextBox1.
If indexToText >= 0 Then
returnValue = indexToText
End If
End If
Return returnValue
End Function
So I would like to have this set up where I call the next (overloaded) FIND with the
shortcut <F3>, but I cannot seem to be able to programmatically determine what *integer* to
plug in as the "start"
parameter. So it fails, unless I put in a hardcoded "0", for instance,
and then it will again find the first instance... I know this is wrong, but I'm stuck as to
how to send the correct location of the cursor in the RTB control during run mode...
Thanks in advance,
Dobe <dobe@eskimo.com>
PS: I could send complete ZIP'ped examples to anyone willing to take a look at this, if that
would help...