Home All Groups Group Topic Archive Search About

A much simpler question re subroutines

Author
16 Dec 2006 8:10 PM
aalaan
OK, I'm tussling with the strip strings out of old random file problem, and
the dozens of replies (including experts correcting each other, which has
confused this poor beginner).

Meanwhile here is something *much* simpler and I suspect it again shows how
hard it is to make the transition in thinking that is necessary for going
from old procedural code to vb.

I have discovered that when I read my old random access file wherever there
were '&' in the data I now see '_'. Now I could blindfoldedly code a
solution in QB. I would simply create a subroutine to check for any '_' in
each string and substitute '&'. I would gosub for each field. Obviously that
is not the way for vb. What is the STEP by STEP procedure for RAW beginners
please?

Author
16 Dec 2006 8:25 PM
Rick Rothstein (MVP - VB)
> I have discovered that when I read my old random access file
> wherever there were '&' in the data I now see '_'.

Explain the "I now see" part... how are you "seeing" this? Are you looking
at the file in a Hex editor/viewer or printing it somewhere? Is this in a
pure text file or one of your random access binary files that contains
String data mixed in?


> Now I could blindfoldedly code a solution in QB. I would simply
> create a subroutine to check for any '_' in each string and
> substitute '&'. I would gosub for each field. Obviously that is not the
> way for vb. What is the STEP by STEP procedure
> for RAW beginners please?

Assuming you just want to change this character after having read it into
your program, you could use VB6's Replace function to do this...

FixedText = Replace(OldTextString, "_", "&")

This will change all occurrence of underline characters in your
OldTextString to ampersands.


Rick
Author
16 Dec 2006 8:44 PM
aalaan
"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
message news:ezA%23ZBVIHHA.4992@TK2MSFTNGP04.phx.gbl...
>> I have discovered that when I read my old random access file
>> wherever there were '&' in the data I now see '_'.
>
> Explain the "I now see" part... how are you "seeing" this? Are you looking
> at the file in a Hex editor/viewer or printing it somewhere? Is this in a
> pure text file or one of your random access binary files that contains
> String data mixed in?

I've got a form working that shows in text boxes the stripped out data
strings.
Show quoteHide quote
>
>
>> Now I could blindfoldedly code a solution in QB. I would simply
>> create a subroutine to check for any '_' in each string and
>> substitute '&'. I would gosub for each field. Obviously that is not the
>> way for vb. What is the STEP by STEP procedure
>> for RAW beginners please?
>
> Assuming you just want to change this character after having read it into
> your program, you could use VB6's Replace function to do this...
>
> FixedText = Replace(OldTextString, "_", "&")
>
> This will change all occurrence of underline characters in your
> OldTextString to ampersands.
>
Yes, I understandd that Rick, but I want to avoid using that line of cdoe
for every filed. That's why in the olf days I would write it in a subrouine
and Gosub for each field. I sense that is the wrong approach in vb

Show quoteHide quote
>
> Rick
>
Author
16 Dec 2006 9:02 PM
Rick Rothstein (MVP - VB)
>> Assuming you just want to change this character after having read it into
>> your program, you could use VB6's Replace function to do this...
>>
>> FixedText = Replace(OldTextString, "_", "&")
>>
>> This will change all occurrence of underline characters in your
>> OldTextString to ampersands.
>>
> Yes, I understandd that Rick, but I want to avoid using that line of cdoe
> for every filed. That's why in the olf days I would write it in a
> subrouine and Gosub for each field. I sense that is the wrong approach in
> vb

You can let VB do it automatically for you. I would think this Change event
code for your TextBox would do what you want...

Private Sub Text1_Change()
  Dim Location As Long
  Location = Text1.SelStart
  Text1.Text = Replace(Text1.Text, "_", "&")
  Text1.SelStart = Location
  Debug.Print "X"
End Sub


Now, no matter what you put in the TextBox (named Text1), it will
automatically remove underlines and replace them with ampersands.

Rick
Author
16 Dec 2006 9:13 PM
aalaan
But do I have to do that for every field, ie Text1, Text2, Text3 and so on?

Show quoteHide quote
"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
message news:%23XQxzVVIHHA.1124@TK2MSFTNGP03.phx.gbl...
>>> Assuming you just want to change this character after having read it
>>> into your program, you could use VB6's Replace function to do this...
>>>
>>> FixedText = Replace(OldTextString, "_", "&")
>>>
>>> This will change all occurrence of underline characters in your
>>> OldTextString to ampersands.
>>>
>> Yes, I understandd that Rick, but I want to avoid using that line of cdoe
>> for every filed. That's why in the olf days I would write it in a
>> subrouine and Gosub for each field. I sense that is the wrong approach in
>> vb
>
> You can let VB do it automatically for you. I would think this Change
> event code for your TextBox would do what you want...
>
> Private Sub Text1_Change()
>  Dim Location As Long
>  Location = Text1.SelStart
>  Text1.Text = Replace(Text1.Text, "_", "&")
>  Text1.SelStart = Location
>  Debug.Print "X"
> End Sub
>
>
> Now, no matter what you put in the TextBox (named Text1), it will
> automatically remove underlines and replace them with ampersands.
>
> Rick
>
Author
16 Dec 2006 9:22 PM
Mike Williams
"aalaan" <aal***@tpg.com.au> wrote in message
news:4584616e@dnews.tpgi.com.au...

> But do I have to do that for every field, ie Text1, Text2, Text3 and so
> on?

Just write your own "Gosub" routine to do what you want (since you can write
it blindfolded) and we'll look at it for you. Don't forget to post all of
the relevant code, including all of the variable declarations.

Mike
Author
17 Dec 2006 12:02 AM
Rick Rothstein (MVP - VB)
"aalaan" <aal***@tpg.com.au> wrote in message
news:4584616e@dnews.tpgi.com.au...
> But do I have to do that for every field, ie Text1, Text2, Text3 and so
> on?

Okay, that is true, but we can make it a little less painful then. Add a
(BAS) Module to your project and put the following code into it...

     Public Sub FixText()
       Dim Location As Long
       With Screen.ActiveForm.ActiveControl
         Location = .SelStart
         .Text = Replace(.Text, "_", "&")
         .SelStart = Location
       End With
     End Sub

Now, just add this single line to the Change events for your TextBoxes

     FixText

and all will be taken care of for you.

Rick


Show quoteHide quote
> "Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
> message news:%23XQxzVVIHHA.1124@TK2MSFTNGP03.phx.gbl...
>>>> Assuming you just want to change this character after having read it
>>>> into your program, you could use VB6's Replace function to do this...
>>>>
>>>> FixedText = Replace(OldTextString, "_", "&")
>>>>
>>>> This will change all occurrence of underline characters in your
>>>> OldTextString to ampersands.
>>>>
>>> Yes, I understandd that Rick, but I want to avoid using that line of
>>> cdoe for every filed. That's why in the olf days I would write it in a
>>> subrouine and Gosub for each field. I sense that is the wrong approach
>>> in vb
>>
>> You can let VB do it automatically for you. I would think this Change
>> event code for your TextBox would do what you want...
>>
>> Private Sub Text1_Change()
>>  Dim Location As Long
>>  Location = Text1.SelStart
>>  Text1.Text = Replace(Text1.Text, "_", "&")
>>  Text1.SelStart = Location
>>  Debug.Print "X"
>> End Sub
>>
>>
>> Now, no matter what you put in the TextBox (named Text1), it will
>> automatically remove underlines and replace them with ampersands.
>>
>> Rick
>>
>
>
Author
17 Dec 2006 12:14 AM
aalaan
Rick

Thank you thank you! I was snivelling in my tea when I got your reply. I
have put that code in the bas module I've created. Now can't find the change
events for my buttons. Presumably that's not in the property list

Show quoteHide quote
"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
message news:%23ZnKq6WIHHA.5000@TK2MSFTNGP03.phx.gbl...
>
> "aalaan" <aal***@tpg.com.au> wrote in message
> news:4584616e@dnews.tpgi.com.au...
>> But do I have to do that for every field, ie Text1, Text2, Text3 and so
>> on?
>
> Okay, that is true, but we can make it a little less painful then. Add a
> (BAS) Module to your project and put the following code into it...
>
>     Public Sub FixText()
>       Dim Location As Long
>       With Screen.ActiveForm.ActiveControl
>         Location = .SelStart
>         .Text = Replace(.Text, "_", "&")
>         .SelStart = Location
>       End With
>     End Sub
>
> Now, just add this single line to the Change events for your TextBoxes
>
>     FixText
>
> and all will be taken care of for you.
>
> Rick
>
>
>> "Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
>> message news:%23XQxzVVIHHA.1124@TK2MSFTNGP03.phx.gbl...
>>>>> Assuming you just want to change this character after having read it
>>>>> into your program, you could use VB6's Replace function to do this...
>>>>>
>>>>> FixedText = Replace(OldTextString, "_", "&")
>>>>>
>>>>> This will change all occurrence of underline characters in your
>>>>> OldTextString to ampersands.
>>>>>
>>>> Yes, I understandd that Rick, but I want to avoid using that line of
>>>> cdoe for every filed. That's why in the olf days I would write it in a
>>>> subrouine and Gosub for each field. I sense that is the wrong approach
>>>> in vb
>>>
>>> You can let VB do it automatically for you. I would think this Change
>>> event code for your TextBox would do what you want...
>>>
>>> Private Sub Text1_Change()
>>>  Dim Location As Long
>>>  Location = Text1.SelStart
>>>  Text1.Text = Replace(Text1.Text, "_", "&")
>>>  Text1.SelStart = Location
>>>  Debug.Print "X"
>>> End Sub
>>>
>>>
>>> Now, no matter what you put in the TextBox (named Text1), it will
>>> automatically remove underlines and replace them with ampersands.
>>>
>>> Rick
>>>
>>
>>
>
>
Author
17 Dec 2006 12:19 AM
Bob O`Bob
aalaan wrote:
> Rick
>
> Thank you thank you! I was snivelling in my tea when I got your reply. I
> have put that code in the bas module I've created. Now can't find the change
> events for my buttons. Presumably that's not in the property list


it will be, but you have to select a button first.
--
Author
17 Dec 2006 12:31 AM
aalaan
I did and still can't find it. Using VB5. Is it in front of my nose? I'll go
and look again.

Show quoteHide quote
"Bob O`Bob" <filter***@yahoogroups.com> wrote in message
news:%23aRDSEXIHHA.1816@TK2MSFTNGP06.phx.gbl...
> aalaan wrote:
>> Rick
>>
>> Thank you thank you! I was snivelling in my tea when I got your reply. I
>> have put that code in the bas module I've created. Now can't find the
>> change events for my buttons. Presumably that's not in the property list
>
>
> it will be, but you have to select a button first.
> --
Author
17 Dec 2006 12:46 AM
Rick Rothstein (MVP - VB)
> ... Using VB5 ...

Whoops! If you posted that earlier in any of your threads, I missed it. You
won't be able to use code I posted as the Replace function which it makes
use of wasn't added to VB until VB6. The structure I gave you (using a
Module to hold the "global" code and using Screen.ActiveForm.ActiveControl
reference will work alright, but you will need to replace the Replace
function all I posted with code that duplicates its functionality).
Searching the web returned the code I added after my signature which is a
function that will duplicate VB6's Replace function. It was created by
Francesco Balena and here is a link to the web page I found it on...

http://www.devx.com/vb2themax/Tip/18933

To make use of it, simply paste it into your BAS Module (that is all you
need to do, it will be usable from anywhere within your project after that).

Rick

Public Function Replace(Source As String, Find As String, ReplaceStr As
String, _
    Optional ByVal Start As Long = 1, Optional Count As Long = -1, _
    Optional Compare As VbCompareMethod = vbBinaryCompare) As String

    Dim findLen As Long
    Dim replaceLen As Long
    Dim index As Long
    Dim counter As Long

    findLen = Len(Find)
    replaceLen = Len(ReplaceStr)
    ' this prevents an endless loop
    If findLen = 0 Then Err.Raise 5

    If Start < 1 Then Start = 1
    index = Start

    ' let's start by assigning the source to the result
    Replace = Source

    ' if Find and ReplaceStr strings have same length, it is possible to
    ' use an optimized algorithm, based on the Mid$ command
    Do
        index = InStr(index, Replace, Find, Compare)
        If index = 0 Then Exit Do
        If findLen = replaceLen Then
            ' if the find and replace strings have same length
            ' we can use the faster Mid$ command
            Mid$(Replace, index, findLen) = ReplaceStr
        Else
            ' else we must use concatenation
            Replace = Left$(Replace, index - 1) & ReplaceStr & Mid$(Replace,
_
                index + findLen)
        End If
        ' skip over the string just added
        index = index + replaceLen
        ' increment the replacement counter
        counter = counter + 1
        ' Note that the Loop Until test will always fail if Count = -1
    Loop Until counter = Count

    ' The next operation serves to keep complete compatibility with
    ' VB6's Replace function. You can delete it if you prefer.
    If Start > 1 Then Replace = Mid$(Replace, Start)

End Function
Author
17 Dec 2006 12:29 AM
Rick Rothstein (MVP - VB)
> Thank you thank you! I was snivelling in my tea when I got your reply. I
> have put that code in the bas module I've created. Now can't find the
> change events for my buttons. Presumably that's not in the property list

Change events for your "buttons"? We were talking about TextBoxes... Change
events for TextBoxes.

The BAS Module is only for code you add... the Change event procedures are
back on the form where the TextBoxes are situated. That is one of the
beauties of using a Module... you can put your "global" code there and then
leave it. Everything else you do will be as before (you don't have to change
anything else). Go to the form where the TextBoxes are and double click one
of them just like you did before adding the Module... when you put the
FixText statement in the Change event, VB will automatically know how to
call the Sub on the Module because it is declared as Public.

Rick
Author
17 Dec 2006 12:44 AM
aalaan
Sorry. I did mean text boxes!

"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
message news:enLpqJXIHHA.3780@TK2MSFTNGP02.phx.gbl...
> Change events for your "buttons"? We were talking about TextBoxes...
> Change events for TextBoxes.
>
> The BAS Module is only for code you add... the Change event procedures are
> back on the form where the TextBoxes are situated. That is one of the
> beauties of using a Module... you can put your "global" code there and
> then leave it. Everything else you do will be as before (you don't have to
> change anything else). Go to the form where the TextBoxes are and double
> click one of them just like you did before adding the Module... when you
> put the FixText statement in the Change event

But I didn't do that. I placed the variable in the properties list on the
IDE.

> VB will automatically know how to call the Sub on the Module because it is
> declared as Public.
>
> Rick
Again thanks for your patience. You are getting me there!
Author
17 Dec 2006 12:54 AM
aalaan
Horror of horrors. This probably explains it. They are NOT text boxes. I
used Labels as the data appearing in them isn't to be changed, just read
from the existing file! Apologies for the misunderstanding. Put it down to
stupidity! What now?

Show quoteHide quote
"aalaan" <aal***@tpg.com.au> wrote in message
news:458492ff@dnews.tpgi.com.au...
> Sorry. I did mean text boxes!
>
> "Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
> message news:enLpqJXIHHA.3780@TK2MSFTNGP02.phx.gbl...
>> Change events for your "buttons"? We were talking about TextBoxes...
>> Change events for TextBoxes.
>>
>> The BAS Module is only for code you add... the Change event procedures
>> are back on the form where the TextBoxes are situated. That is one of the
>> beauties of using a Module... you can put your "global" code there and
>> then leave it. Everything else you do will be as before (you don't have
>> to change anything else). Go to the form where the TextBoxes are and
>> double click one of them just like you did before adding the Module...
>> when you put the FixText statement in the Change event
>
> But I didn't do that. I placed the variable in the properties list on the
> IDE.
>
>> VB will automatically know how to call the Sub on the Module because it
>> is declared as Public.
>>
>> Rick
> Again thanks for your patience. You are getting me there!
>
>
Author
17 Dec 2006 1:17 AM
Rick Rothstein (MVP - VB)
> Horror of horrors. This probably explains it. They are NOT text boxes. I
> used Labels as the data appearing in them isn't to be changed, just read
> from the existing file! Apologies for the misunderstanding. Put it down to
> stupidity! What now?

The simplest thing to do is replace the Label controls with TextBox controls
and set the Locked property for each TextBox to True. Doing this will make
it so the user can't change it contents; but, if it matters to you, the
TextBoxes will still be able to be selected by the user (that way they can
copy text from it to the Clipboard).

Note: I will be stepping out for the rest of the evening. If any questions
about my stuff remains unanswered by other volunteers here, I try to address
them when I get back in.

Rick
Author
17 Dec 2006 1:25 AM
Henning
As someone earlier sugested somewhere, set all labels UseMnemonic property
to False to see if that helps.

/Henning

Show quoteHide quote
"aalaan" <aal***@tpg.com.au> skrev i meddelandet
news:45849545$1@dnews.tpgi.com.au...
> Horror of horrors. This probably explains it. They are NOT text boxes. I
> used Labels as the data appearing in them isn't to be changed, just read
> from the existing file! Apologies for the misunderstanding. Put it down to
> stupidity! What now?
>
> "aalaan" <aal***@tpg.com.au> wrote in message
> news:458492ff@dnews.tpgi.com.au...
> > Sorry. I did mean text boxes!
> >
> > "Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
> > message news:enLpqJXIHHA.3780@TK2MSFTNGP02.phx.gbl...
> >> Change events for your "buttons"? We were talking about TextBoxes...
> >> Change events for TextBoxes.
> >>
> >> The BAS Module is only for code you add... the Change event procedures
> >> are back on the form where the TextBoxes are situated. That is one of
the
> >> beauties of using a Module... you can put your "global" code there and
> >> then leave it. Everything else you do will be as before (you don't have
> >> to change anything else). Go to the form where the TextBoxes are and
> >> double click one of them just like you did before adding the Module...
> >> when you put the FixText statement in the Change event
> >
> > But I didn't do that. I placed the variable in the properties list on
the
> > IDE.
> >
> >> VB will automatically know how to call the Sub on the Module because it
> >> is declared as Public.
> >>
> >> Rick
> > Again thanks for your patience. You are getting me there!
> >
> >
>
>
Author
17 Dec 2006 6:02 PM
Rick Rothstein (MVP - VB)
> This probably explains it.
> They are NOT text boxes.
> I  used Labels

That definitely explains it... there is **nothing** wrong with your data...
you are seeing a natural (default) way that a Label control works. In case
you are unaware of it, the Caption property of a Label has a 'feature' that
can be quite handy. Let's say you had a TextBox that you wanted to give an
Alt+{character} short-cut keystroke to (just like those underlined
characters in Windows menus... if you don't see them on your system by
default, press the Alt key and they will appear)... how would you do it?
Simple, add a Label control, place it next to the TextBox, set the TabIndex
property for the TextBox to be one greater than that for the Label, and set
the Label's Caption property to whatever you want placing an ampersand in
front of the letter you want to use as the short-cut. For example, let's say
the identifying text for the TextBox is "User Name" and you want the user to
press Alt+N to be able to go directly to that particular TextBox. Set the
TabIndex properties for the Label and TextBox as I mentioned above and use
this for the Label's Caption property

     Label1.Caption = "User &Name"

The Alt+N keystroke will attempt to take the user to the Label control
(because of the short-cut you set up); but, since Label controls can't take
focus, the focus will move from the Label to the next control in the
TabIndex sequence.

By the way, had you described your problem originally by saying the
ampersand symbols were removed and LETTERS WERE BEING UNDERLINED (instead of
simply saying ampersands were becoming underline characters), we might have
guessed at the problem quicker... I think we were all thrown by your
description of the problem coupled with the fact that it was **old** data
generated from a long time ago.

Rick
Author
17 Dec 2006 7:15 PM
Bob Butler
"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
message news:%232D49VgIHHA.3952@TK2MSFTNGP02.phx.gbl
<cut>
> By the way, had you described your problem originally by saying the
> ampersand symbols were removed and LETTERS WERE BEING UNDERLINED
> (instead of simply saying ampersands were becoming underline
> characters), we might have guessed at the problem quicker... I think
> we were all thrown by your description of the problem coupled with
> the fact that it was **old** data generated from a long time ago.

Speak for yourself! My first reply regarding this was to ask how it was
being displayed and if it were in Labels to set the UseMnemonic property to
False.  <g>

I gave up when the OP didn't answer me, or anybody else, about how he was
displaying the data.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
17 Dec 2006 8:05 PM
aalaan
Show quote Hide quote
"Bob Butler" <tiredofit@nospam.ever> wrote in message
news:epEeF$gIHHA.3952@TK2MSFTNGP02.phx.gbl...
> "Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
> message news:%232D49VgIHHA.3952@TK2MSFTNGP02.phx.gbl
> <cut>
>> By the way, had you described your problem originally by saying the
>> ampersand symbols were removed and LETTERS WERE BEING UNDERLINED
>> (instead of simply saying ampersands were becoming underline
>> characters), we might have guessed at the problem quicker... I think
>> we were all thrown by your description of the problem coupled with
>> the fact that it was **old** data generated from a long time ago.
>
> Speak for yourself! My first reply regarding this was to ask how it was
> being displayed and if it were in Labels to set the UseMnemonic property
> to
> False.  <g>
>
> I gave up when the OP didn't answer me, or anybody else, about how he was
> displaying the data.

The OP (me!) didn't answer you due to an oversight and the sheer amount of
information I'm trying to plough through. Thanks for trying. I've now been
invited to post my entire code to a regular direct and he will endeavour to
show me how.
Show quoteHide quote
> --
> Reply to the group so all can participate
> VB.Net: "Fool me once..."
>
Author
18 Dec 2006 6:30 AM
Jim Carlock
"aalaan" <inva***@invalid.com> posted...
: The OP (me!) didn't answer you due to an oversight and the
: sheer amount of information I'm trying to plough through.

Also note, that labels and textboxes both have something
like 32000 character limits. If any of the files you're reading
from are bigger than 32,000 characters in size, you'd be
better off with a RichTextBox control. There's a .Locked
property on textboxes as well, that doesn't gray out the text,
that prevents the enduser from changing the text. That should
effectively get you to where you want to go.

Hope this helps.

--
Jim Carlock
Post replies to the group.
Author
17 Dec 2006 7:17 PM
aalaan
OK Rick, understood (I think)

But I don't think the letters *were* being underlined. Just underscores
where there were ampersands. BTW, someone was telling me that I should use
text boxes and set them so they couldn't be updated. I remember now that I
originally did that but found the recovered data got greyed out and I wanted
it bold and coloured on the form (but not updatable), which is why I changed
them all to labels.

Can I ask you about the bas module now. Is that in fact a public module and
in effect could be used to hold the main code, ie all the dims. I could then
use the button subs (procedures?) to do my various things. That is where I'm
confused with the UDT etc. Where do I put that code? Mike has tried to
explain how to use it in another thread. I have printed that out and am
going to study it - it seems he (and probably others) and trying to tell me
that there is a simpler way to do eg Biggins = Mid$(Bloggs$,3,4)) but do I
dim first and where?

Show quoteHide quote
"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
message news:%232D49VgIHHA.3952@TK2MSFTNGP02.phx.gbl...
>> This probably explains it.
>> They are NOT text boxes.
>> I  used Labels
>
> That definitely explains it... there is **nothing** wrong with your
> data... you are seeing a natural (default) way that a Label control works.
> In case you are unaware of it, the Caption property of a Label has a
> 'feature' that can be quite handy. Let's say you had a TextBox that you
> wanted to give an Alt+{character} short-cut keystroke to (just like those
> underlined characters in Windows menus... if you don't see them on your
> system by default, press the Alt key and they will appear)... how would
> you do it? Simple, add a Label control, place it next to the TextBox, set
> the TabIndex property for the TextBox to be one greater than that for the
> Label, and set the Label's Caption property to whatever you want placing
> an ampersand in front of the letter you want to use as the short-cut. For
> example, let's say the identifying text for the TextBox is "User Name" and
> you want the user to press Alt+N to be able to go directly to that
> particular TextBox. Set the TabIndex properties for the Label and TextBox
> as I mentioned above and use this for the Label's Caption property
>
>     Label1.Caption = "User &Name"
>
> The Alt+N keystroke will attempt to take the user to the Label control
> (because of the short-cut you set up); but, since Label controls can't
> take focus, the focus will move from the Label to the next control in the
> TabIndex sequence.
>
> By the way, had you described your problem originally by saying the
> ampersand symbols were removed and LETTERS WERE BEING UNDERLINED (instead
> of simply saying ampersands were becoming underline characters), we might
> have guessed at the problem quicker... I think we were all thrown by your
> description of the problem coupled with the fact that it was **old** data
> generated from a long time ago.
>
> Rick
>
Author
20 Dec 2006 4:13 PM
Dave O.
"aalaan" <aal***@tpg.com.au> wrote in message
news:458597e7@dnews.tpgi.com.au...

>  BTW, someone was telling me that I should use text boxes and set them so
> they couldn't be updated. I remember now that I originally did that but
> found the recovered data got greyed out and I wanted it bold and coloured
> on the form (but not updatable.

Read carefully what people tell you. If you set the TextBox to Disabled then
you get what you describe above, if however you did what was suggested and
set the TextBox to Locked they retain colour, boldness etc. but cannot be
edited.

Regards
Dave O.
Author
20 Dec 2006 6:24 PM
aalaan
Thanks. Mike is teaching me patiently how to use labels for the same
outcome.

Show quoteHide quote
"Dave O." <nob***@nowhere.com> wrote in message
news:%231c8%23GFJHHA.1468@TK2MSFTNGP04.phx.gbl...
>
> "aalaan" <aal***@tpg.com.au> wrote in message
> news:458597e7@dnews.tpgi.com.au...
>
>>  BTW, someone was telling me that I should use text boxes and set them so
>> they couldn't be updated. I remember now that I originally did that but
>> found the recovered data got greyed out and I wanted it bold and coloured
>> on the form (but not updatable.
>
> Read carefully what people tell you. If you set the TextBox to Disabled
> then you get what you describe above, if however you did what was
> suggested and set the TextBox to Locked they retain colour, boldness etc.
> but cannot be edited.
>
> Regards
> Dave O.
>
Author
21 Dec 2006 6:52 AM
Mike Williams
"aalaan" <inva***@invalid.com> wrote in message
news:45897feb$1@dnews.tpgi.com.au...

> Thanks. Mike is teaching me patiently how to use
> labels for the same outcome.

Actually, just for the record, I'm sticking with your Labels for the time
being (because there are other more important points to cover) but I will
(soon) advise you to change to using Text Boxes, so that your users can
amend your data (if you give them permission, of course) and I'll show you
at least two different methods of achieving the effect you want with them.

Mike
Author
21 Dec 2006 5:20 PM
aalaan
Hi Mike. Multiple communication channels! I specifically do NOT under any
circumstances want anyone being able to do any other than READ the existing
data, so I want to keep the labels for this application, but of course there
will later be other apps where I might.

Show quoteHide quote
"Mike Williams" <M***@WhiskyAndCoke.com> wrote in message
news:eSbqJyMJHHA.1424@TK2MSFTNGP04.phx.gbl...
> "aalaan" <inva***@invalid.com> wrote in message
> news:45897feb$1@dnews.tpgi.com.au...
>
>> Thanks. Mike is teaching me patiently how to use
>> labels for the same outcome.
>
> Actually, just for the record, I'm sticking with your Labels for the time
> being (because there are other more important points to cover) but I will
> (soon) advise you to change to using Text Boxes, so that your users can
> amend your data (if you give them permission, of course) and I'll show you
> at least two different methods of achieving the effect you want with them.
>
> Mike
>
>
>
Author
21 Dec 2006 5:36 PM
Mike Williams
"aalaan" <inva***@invalid.com> wrote in message
news:458ac25d$1@dnews.tpgi.com.au...

> Hi Mike. Multiple communication channels! I specifically do NOT
> under any circumstances want anyone being able to do any other
> than READ the existing data, so I want to keep the labels for this
> application, but of course there will later be other apps where I might.

That's okay. I posted my response on the newsgroup just to set the records
straight in case others here thought I had been telling you that you
couldn't "lock the user out of editing your data" and also maintain its full
visibility without using Labels, which of course is not the case. By the
way, you're awake early aren't you ;-)

Mike
Author
17 Dec 2006 12:20 AM
Rick Rothstein (MVP - VB)
> ... Add a (BAS) Module to your project ...

I just read of your confusion of this instruction elsewhere in your other
thread. Adding a BAS Module is simple. You do just like you do to add
another form to your project (select Project from VB's menu bar); but,
instead of selecting "Add Form" from the menu that opens, select "Add
Module" instead. That will add a code window to your project for the module.
Any variables, Subs or Functions declared as Public (or, for just the
variables, declared with a Dim), will be available to your whole project...
any code procedure anywhere in your project will be able to "see" and make
use of them. Things declared as Private will only be available on the Module
itself. Oh, and the reason it is sometimes referred to as a BAS Module is
because when you save the module as part of your project, it will
automatically have a .BAS extension on the file name.

Rick
Author
17 Dec 2006 12:32 AM
aalaan
Thanks you very much for that explanation. The fog is beginning to lift (he
hopes <g>)

Show quoteHide quote
"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
message news:uVL63EXIHHA.1816@TK2MSFTNGP06.phx.gbl...
>> ... Add a (BAS) Module to your project ...
>
> I just read of your confusion of this instruction elsewhere in your other
> thread. Adding a BAS Module is simple. You do just like you do to add
> another form to your project (select Project from VB's menu bar); but,
> instead of selecting "Add Form" from the menu that opens, select "Add
> Module" instead. That will add a code window to your project for the
> module. Any variables, Subs or Functions declared as Public (or, for just
> the variables, declared with a Dim), will be available to your whole
> project... any code procedure anywhere in your project will be able to
> "see" and make use of them. Things declared as Private will only be
> available on the Module itself. Oh, and the reason it is sometimes
> referred to as a BAS Module is because when you save the module as part of
> your project, it will automatically have a .BAS extension on the file
> name.
>
> Rick
>
Author
16 Dec 2006 8:27 PM
Bob Butler
Show quote Hide quote
"aalaan" <aal***@tpg.com.au> wrote in message
news:4584529d$1@dnews.tpgi.com.au
> OK, I'm tussling with the strip strings out of old random file
> problem, and the dozens of replies (including experts correcting each
> other, which has confused this poor beginner).
>
> Meanwhile here is something *much* simpler and I suspect it again
> shows how hard it is to make the transition in thinking that is
> necessary for going from old procedural code to vb.
>
> I have discovered that when I read my old random access file wherever
> there were '&' in the data I now see '_'. Now I could blindfoldedly
> code a solution in QB. I would simply create a subroutine to check
> for any '_' in each string and substitute '&'. I would gosub for each
> field. Obviously that is not the way for vb. What is the STEP by STEP
> procedure for RAW beginners please?

How are you looking at the data?  If you are displaying it in a label then
you should set the .UseMnemonic property to False to prevent VB from
treating & as flagging an accelerator key.  There's no reason for VB to be
converting & to _ so there's something happening in the way you are reading
the strings, extracting the fields from them or displaying them.  The people
who've been trying to get you to convert to reading a UDT or a Byte array
instead of a String have been trying to help you avoid data corruption
issues with the old String methods that are documented not to be reliable as
of VB4.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
16 Dec 2006 8:48 PM
aalaan
Thanks Bob. I'm *trying* to convert to UDT but having problems with where to
put the code and how to read the results, and do I have to Dim etc. Real
beginner's stuff! See my answer to Rick. I'm reading the stripped out
strings into text boxes on a form. As you say (I think), there seems no
reason why pure data strings should have the & changed to a _. I am
wondering now if that problem was caused when the files were originally
created!


Show quoteHide quote
"Bob Butler" <tiredofit@nospam.ever> wrote in message
news:eRkCuCVIHHA.2456@TK2MSFTNGP06.phx.gbl...
> "aalaan" <aal***@tpg.com.au> wrote in message
> news:4584529d$1@dnews.tpgi.com.au
>> OK, I'm tussling with the strip strings out of old random file
>> problem, and the dozens of replies (including experts correcting each
>> other, which has confused this poor beginner).
>>
>> Meanwhile here is something *much* simpler and I suspect it again
>> shows how hard it is to make the transition in thinking that is
>> necessary for going from old procedural code to vb.
>>
>> I have discovered that when I read my old random access file wherever
>> there were '&' in the data I now see '_'. Now I could blindfoldedly
>> code a solution in QB. I would simply create a subroutine to check
>> for any '_' in each string and substitute '&'. I would gosub for each
>> field. Obviously that is not the way for vb. What is the STEP by STEP
>> procedure for RAW beginners please?
>
> How are you looking at the data?  If you are displaying it in a label then
> you should set the .UseMnemonic property to False to prevent VB from
> treating & as flagging an accelerator key.  There's no reason for VB to be
> converting & to _ so there's something happening in the way you are
> reading
> the strings, extracting the fields from them or displaying them.  The
> people
> who've been trying to get you to convert to reading a UDT or a Byte array
> instead of a String have been trying to help you avoid data corruption
> issues with the old String methods that are documented not to be reliable
> as
> of VB4.
>
> --
> Reply to the group so all can participate
> VB.Net: "Fool me once..."
>
Author
16 Dec 2006 9:36 PM
Bob Butler
"aalaan" <aal***@tpg.com.au> wrote in message
news:45845b96$1@dnews.tpgi.com.au
> Thanks Bob. I'm *trying* to convert to UDT but having problems with
> where to put the code and how to read the results, and do I have to
> Dim etc. Real beginner's stuff! See my answer to Rick. I'm reading
> the stripped out strings into text boxes on a form. As you say (I
> think), there seems no reason why pure data strings should have the &
> changed to a _. I am wondering now if that problem was caused when
> the files were originally created!

I think the first thing you need to do is look at the file with a hex
editor, or even notepad, and determine if the underscores are or are not in
the saved data.  Make a copy of the file and look at that so you don't risk
corrupting it.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
16 Dec 2006 9:18 PM
Mike Williams
"aalaan" <aal***@tpg.com.au> wrote in message
news:4584529d$1@dnews.tpgi.com.au...

> OK, I'm tussling with the strip strings out of old random file problem,
> and  the dozens of replies (including experts correcting each other,
> which has confused this poor beginner).

You're rapidly becoming a cocky little pain in the arse, Aalaan.

Mike
Author
16 Dec 2006 11:28 PM
aalaan
Not intended. Don't bother any more Mike.

Show quoteHide quote
"Mike Williams" <M***@WhiskyAndCoke.com> wrote in message
news:%23fkhDfVIHHA.1276@TK2MSFTNGP04.phx.gbl...
> "aalaan" <aal***@tpg.com.au> wrote in message
> news:4584529d$1@dnews.tpgi.com.au...
>
>> OK, I'm tussling with the strip strings out of old random file problem,
>> and  the dozens of replies (including experts correcting each other,
>> which has confused this poor beginner).
>
> You're rapidly becoming a cocky little pain in the arse, Aalaan.
>
> Mike
>
>
>
Author
16 Dec 2006 10:11 PM
Bob O`Bob
aalaan wrote:
Show quoteHide quote
> OK, I'm tussling with the strip strings out of old random file problem, and
> the dozens of replies (including experts correcting each other, which has
> confused this poor beginner).
>
> Meanwhile here is something *much* simpler and I suspect it again shows how
> hard it is to make the transition in thinking that is necessary for going
> from old procedural code to vb.
>
> I have discovered that when I read my old random access file wherever there
> were '&' in the data I now see '_'. Now I could blindfoldedly code a
> solution in QB. I would simply create a subroutine to check for any '_' in
> each string and substitute '&'. I would gosub for each field. Obviously that
> is not the way for vb. What is the STEP by STEP procedure for RAW beginners
> please?
>
>


It may appear to be a simpler question, but simply answering it for you
will most likely provide a sub-optimal learning experience.

You need to learn *why* it happened - fixing it should be a MUCH lower priority,
especially given the probability that learning why it happened will lead you to
preventing it in the first place.


    Bob
--
Author
17 Dec 2006 8:16 AM
J French
On Sun, 17 Dec 2006 07:10:03 +1100, "aalaan" <aal***@tpg.com.au>
wrote:

<snip>

>I have discovered that when I read my old random access file wherever there
>were '&' in the data I now see '_'. Now I could blindfoldedly code a
>solution in QB. I would simply create a subroutine to check for any '_' in
>each string and substitute '&'. I would gosub for each field.

DO NOT CHANGE '_' to '&'

With certain controls '&' forces the next letter to be underlined
- you are seeing an underlined space character ( Chr$(32) )

As far as using UDTs - for your App it is a no brainer
- you used to use the Field# n  statement before ?
- UDTs are similar
Author
17 Dec 2006 7:19 PM
aalaan
GOT IT!  Thanks. I now understand perfectly. Just the style for this addled
brain.

Show quoteHide quote
"J French" <erew***@nowhere.uk> wrote in message
news:4584fbbb.1382339@news.btclick.com...
> On Sun, 17 Dec 2006 07:10:03 +1100, "aalaan" <aal***@tpg.com.au>
> wrote:
>
> <snip>
>
>>I have discovered that when I read my old random access file wherever
>>there
>>were '&' in the data I now see '_'. Now I could blindfoldedly code a
>>solution in QB. I would simply create a subroutine to check for any '_' in
>>each string and substitute '&'. I would gosub for each field.
>
> DO NOT CHANGE '_' to '&'
>
> With certain controls '&' forces the next letter to be underlined
> - you are seeing an underlined space character ( Chr$(32) )
>
> As far as using UDTs - for your App it is a no brainer
> - you used to use the Field# n  statement before ?
> - UDTs are similar
>
>
>
Author
18 Dec 2006 10:04 AM
J French
On Mon, 18 Dec 2006 06:19:17 +1100, "aalaan" <aal***@tpg.com.au>
wrote:

>GOT IT!  Thanks. I now understand perfectly. Just the style for this addled
>brain.

I'm getting a handle on your problem.

You have leapt into VB5 at the deep end and you are getting rattled
because you can't identify what is new and what is old stuff.

Basically it is like walking through a mine field.

I had a similar experience 10 years ago when I jumped from DOS Basic
into VB - it was even nastier as I was under serious time pressure.

VB5 is a very nice language, one can port stuff from DOS pretty
easily, however in VB there are often much cleaner and more elegant
solutions.

What you need to do is play around with test projects, just writing
little bits so you get a feel for it.  Jumping in at the deep end and
trying to write/re-write an entire App (which is what I did) is not
the best way of going about things.

When you run into problems, you'll have a nice simple bit of code to
post, and we'll be able to hack it about mercilessly and show you what
we have learned.

Don't worry, VB is not a mine field, there are a few things to learn
and avoid, but you'll get the idea pretty quickly.
Author
18 Dec 2006 5:56 PM
aalaan
Thank you J French. I think you understand the problem well. I've only been
doing this a few days although I've looked at the language on and off for a
few years.

Show quoteHide quote
"J French" <erew***@nowhere.uk> wrote in message
news:45866516.7511910@news.btclick.com...
> On Mon, 18 Dec 2006 06:19:17 +1100, "aalaan" <aal***@tpg.com.au>
> wrote:
>
>>GOT IT!  Thanks. I now understand perfectly. Just the style for this
>>addled
>>brain.
>
> I'm getting a handle on your problem.
>
> You have leapt into VB5 at the deep end and you are getting rattled
> because you can't identify what is new and what is old stuff.
>
> Basically it is like walking through a mine field.
>
> I had a similar experience 10 years ago when I jumped from DOS Basic
> into VB - it was even nastier as I was under serious time pressure.
>
> VB5 is a very nice language, one can port stuff from DOS pretty
> easily, however in VB there are often much cleaner and more elegant
> solutions.
>
> What you need to do is play around with test projects, just writing
> little bits so you get a feel for it.  Jumping in at the deep end and
> trying to write/re-write an entire App (which is what I did) is not
> the best way of going about things.
>
> When you run into problems, you'll have a nice simple bit of code to
> post, and we'll be able to hack it about mercilessly and show you what
> we have learned.
>
> Don't worry, VB is not a mine field, there are a few things to learn
> and avoid, but you'll get the idea pretty quickly.
>
>
Author
19 Dec 2006 7:48 AM
J French
On Tue, 19 Dec 2006 04:56:47 +1100, "aalaan" <inva***@invalid.com>
wrote:

>Thank you J French. I think you understand the problem well. I've only been
>doing this a few days although I've looked at the language on and off for a
>few years.

I figured so.

It is much easier to write a load of little test Apps, that way you'll
get a feel for VB - and more important, you'll regain your confidence.