How to fix this String to Long Error??

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

I am getting an error Option strict on disallows implicit conversion
from string to long

I get it for this code

iStartPosition = InStr(iStartPosition + 1, RichTextBox1.Text, "A" Or
"a"

the "A" and "a" are underlined in blue. How can I fix this?

Say I want it to be:
iStartPosition = InStr(iStartPosition + 1, RichTextBox1.Text, "A" Or
"a" Or "U" or "u" etc

how can I make this work?
 
Ron said:
I am getting an error Option strict on disallows implicit conversion
from string to long

I get it for this code

iStartPosition = InStr(iStartPosition + 1, RichTextBox1.Text, "A" Or
"a"

the "A" and "a" are underlined in blue. How can I fix this?

Say I want it to be:
iStartPosition = InStr(iStartPosition + 1, RichTextBox1.Text, "A" Or
"a" Or "U" or "u" etc

how can I make this work?

You get that error message because you are using the Or operator on two
strings. As the operator is not defined for strings, it tries to find
the closest match for the data types. The closest match is long, but
there is no automatic conversion from string to long.

You can use the IndexOfAny method to find one of many characters:

startPosition = RichTextBox1.Text.IndexOfAny(New Char() {"A"c, "a"c,
"U"c, "u"c})
 
Ron said:
I am getting an error Option strict on disallows implicit conversion
from string to long

I get it for this code

iStartPosition = InStr(iStartPosition + 1, RichTextBox1.Text, "A" Or
"a"

the "A" and "a" are underlined in blue. How can I fix this?

Say I want it to be:
iStartPosition = InStr(iStartPosition + 1, RichTextBox1.Text, "A" Or
"a" Or "U" or "u" etc

how can I make this work?

Hello Ron, I thought you would have posted back into the original
thread(??), but anyway, to achieve what you're asking just change the
line to the following -

iStartPosition = InStr(iStartPosition + 1, RichTextBox1.Text, "AU-",
CompareMethod.Text)

Note, all I've added is the "CompareMethod.Text"


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
Göran Andersson said:
You can use the IndexOfAny method to find one of many characters:

startPosition = RichTextBox1.Text.IndexOfAny(New Char() {"A"c, "a"c,
"U"c, "u"c})

Göran, Ron is getting a bit confused here. He is actually trying to
find all occurrences of "AU-", "au-", "Au-" or "aU-". If he finds any
A's or U's he'll also find A's & U's in other areas of his text, which
isn't what he originally claimed he wanted.

Please see his original post - "How would I do this??"


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
Yes I guess I should have posted a bit more of my data file because
there are records with aU au AU Au so I need to find variations. some
do not have the dash because people make mistakes.

So I can get a better idea lets say for example I want to find more
than one letter both upper and lower of that letter.....lets say find
Vowels Aa, Ee, Ii, Oo, Uu in that text file, then I can change them
to fit my needs.

How would I go about rewriting the ptrogram to go through and find
vowels no matter where they are part number or not and then they would
count them highlight them green etc.... this way I can then modify to
find the combinations I need. This will give me an idea of how to
find differant combinations.

thanks for all your help with this, but I have not done any string
searching or manipulation and counting of those characters so I have
no idea what I am doing.
 
Ron said:
Yes I guess I should have posted a bit more of my data file because
there are records with aU au AU Au so I need to find variations. some
do not have the dash because people make mistakes.

So I can get a better idea lets say for example I want to find more
than one letter both upper and lower of that letter.....lets say find
Vowels Aa, Ee, Ii, Oo, Uu in that text file, then I can change them
to fit my needs.

How would I go about rewriting the ptrogram to go through and find
vowels no matter where they are part number or not and then they would
count them highlight them green etc.... this way I can then modify to
find the combinations I need. This will give me an idea of how to
find differant combinations.

OK, looks like you're moving right away from what you originally asked
for. Right now I would forget about letters (Vowels or otherwise) and
take a completely different approach.

From what you posted in your other thread, it looks like the unique
character is in fact the hyphen ("-"). I can only go by what you
posted, and if it is correct, then we simply need to look for that.

The modified code for the Loop is therefore -

Do
iStartPosition = InStr(iStartPosition + 1, RichTextBox1.Text, "-")
If iStartPosition > 0 Then
iEndPosition = InStr(iStartPosition, RichTextBox1.Text, " ")
RichTextBox1.Select(iStartPosition - 3, (iEndPosition -
iStartPosition) + 2)
iStartPosition = iEndPosition
RichTextBox1.SelectionColor = Color.Green
iPartNumberCounter += 1
End If
Loop Until iStartPosition = 0
MsgBox(String.Format("Number of Product Codes = {0}", iPartNumberCounter))


This relies on the fact that you've only ever shown or mentioned two
characters preceding the hyphen. If this is not the case then please
post a thorough sample of the Text File, containing a good example of
the variations, so everyone can have a better idea of exactly what
you're trying to read.


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
Ron schreef:
I am getting an error Option strict on disallows implicit conversion
from string to long

I get it for this code

iStartPosition = InStr(iStartPosition + 1, RichTextBox1.Text, "A" Or
"a"

the "A" and "a" are underlined in blue. How can I fix this?

Say I want it to be:
iStartPosition = InStr(iStartPosition + 1, RichTextBox1.Text, "A" Or
"a" Or "U" or "u" etc

how can I make this work?

If I understand it correctly, why not just this: Look for "AU" (you are
looking for any variation of "AU") in the uppercased string of the textbox

iStartPosition = RichTextBox1.Text.ToUpper.IndexOf("AU",iStartposition+1)
 
Yes I think that in fact the unique identifier is AU, because
sometimes the data entry folks do not enter the - by mistake.

However I woyuld like to know how to test for and find other
variations because I have other parts that have starting characters of
AO, XW, and others...for example in another file there are parts that
have a part number of E7 or e7 so would like to know how to search
for multiple instances of differant characters.

Can anyone help me out with that? Hopefully I am being a bit more
specific now, sorry for all the confusion.
so basically i just want to be able to read a file and find and
highlight and count instances of specific letters.
 
Ron said:
Yes I think that in fact the unique identifier is AU, because
sometimes the data entry folks do not enter the - by mistake.

However I woyuld like to know how to test for and find other
variations because I have other parts that have starting characters of
AO, XW, and others...for example in another file there are parts that
have a part number of E7 or e7 so would like to know how to search
for multiple instances of differant characters.

Can anyone help me out with that? Hopefully I am being a bit more
specific now, sorry for all the confusion.
so basically i just want to be able to read a file and find and
highlight and count instances of specific letters.

Ron, if you're only looking for AU/Au/aU/au or other letter
combinations, then the code I provided that contains the
"CompareMethod.Text" will do exactly what you want, just remove the "-".

Your problem is going to be that some of your two letter combinations
are not going to be unique and will appear within other words, not just
Part Numbers. You will still need to find something that makes your
Part Numbers unique.

The offer is still there, if you would like to post a broader example of
your Text File then maybe we can help you discover the unique
combination that will provide you a solution.


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
thanks for all of the help. I modified your code to find vowels but
in my Part number and desctription file. I did this because I want to
get an idea how this works and how to get it to work.

here is what I did:

Private Sub btnprocess_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnprocess.Click
RichTextBox1.Text = My.Computer.FileSystem.ReadAllText("c:
\testfile.txt")
Dim iStartPosition, iEndPosition, iVowel As Integer


Do
iStartPosition = InStr(CStr(iStartPosition + 1),
CStr(RichTextBox1.Text.IndexOfAny(New Char() {"A"c, "a"c, "E"c, "e"c,
"I"c, "i"c, "O"c, "o"c, "U"c, "u"c})))


If iStartPosition > 0 Then
iEndPosition = InStr(iStartPosition,
RichTextBox1.Text, " ")
RichTextBox1.Select(iStartPosition - 1, iEndPosition -
iStartPosition)
iStartPosition = iEndPosition
RichTextBox1.SelectionColor = Color.Green
iVowel += 1
End If
Loop Until iStartPosition = 0
MsgBox(String.Format("Number of vowels = {0}", iVowel))


my text file that looks like this:
Part number descriptions sorted by type and time built
========================================
AU-22453 Thermal paster AU-22468 Thermal paster control AU-22490
Thermal trial packs AU-22628 Control unit plates AU-22615 Paste dust
AU-226221503 NOX Connector

The textfile is displayed in the textbox but the whole first word is
highlighted in Green and none of the other vowels. And the textbox
says only one vowel has been found.

Can you help me fix this? I thought this would have helped me look
for numerous characters, for instance in this case I want to find
vowels.
 
Ron said:
thanks for all of the help. I modified your code to find vowels but
in my Part number and desctription file. I did this because I want to
get an idea how this works and how to get it to work.

here is what I did:

Private Sub btnprocess_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnprocess.Click
RichTextBox1.Text = My.Computer.FileSystem.ReadAllText("c:
\testfile.txt")
Dim iStartPosition, iEndPosition, iVowel As Integer


Do
iStartPosition = InStr(CStr(iStartPosition + 1),
CStr(RichTextBox1.Text.IndexOfAny(New Char() {"A"c, "a"c, "E"c, "e"c,
"I"c, "i"c, "O"c, "o"c, "U"c, "u"c})))

You are mixing up the codes completely. You should use the IndexOfAny
method _instead_ of the InStr function. Now you are making a string
search for the string representation of a number inside the string
representation of the result of a string search.

iStartPosition = RichTextBox1.Text.IndexOfAny(New Char() {"A"c, "a"c,
"E"c, "e"c, "I"c, "i"c, "O"c, "o"c, "U"c, "u"c}), iStartPosition)
If iStartPosition > 0 Then

If iStartPosition said:
iEndPosition = InStr(iStartPosition,
RichTextBox1.Text, " ")

iEndPosition = RichTextBox1.Text.IndexOf(" "c, iStartPosition)
RichTextBox1.Select(iStartPosition - 1, iEndPosition -
iStartPosition)

RichTextBox1.Select(iStartPosition, iEndPosition - iStartPosition)
iStartPosition = iEndPosition
RichTextBox1.SelectionColor = Color.Green
iVowel += 1
End If
Loop Until iStartPosition = 0

Loop Until iStartPosition = -1
 
well with this code all of the words in my file are highlighted in
green except for the last 5 letrters of the last word.
 
That's because you are looking for a space after the part number. You
have to check the result in iEndPosition and use the length of the
string instead, if no space is found after the part number.
 
Back
Top