ReadLine in rich text box?

LBGSHI

Member
Joined
May 9, 2007
Messages
21
Programming Experience
Beginner
Is there an equivalent to ReadLine for rich text boxes? I'm trying to take an input like this:

12345678 9123
45678912 0349
43536363 8383
26736457 9039
37474589 8484

...then add a numeric offset to each line, ignoring everything but the first eight characters of each line, then output each line to a second rich text box, readding those last five characters to each line (" 9123", for example). For example, if the input was what I have above, and the offset was 1, the output would be

12345679 9123
45678913 0349
43536364 8383
26736458 9039
37474590 8484

Does anyone know how I might accomplish this? To compound the matter, I'm going to be doing all of this in hexadecimal, but I think I can figure the conversions out myself, given a good method to read line by line...
 
Both are on, and nothing's showing up. I did revise some of my code since last we talked, so perhaps that's why. What did you find to be erroneous?

And, while I've (possibly) got you here, is there any way you can think of to force IsNumeric to detect A-F as numbers as well as 0-9 (ie, hex)?
 
Dim address = Long.Parse
Why do you declare address as type Object when you want it to be type Long?
 
Why do you declare address as type Object when you want it to be type Long?

Thats what I wanted Option Strict/Explicit to show up - It's no wonder address cannot be ToStringed because "no overload of tostring accepts this number of arguments" - address is Object ergo its ToString() has only one version, no overloads

If address were dimmed as Long, then it would be formattable to hex

I cant understand why it isnt showing, unless Option Strict/Exsplicit havent been turned on it the right place

is there any way you can think of to force IsNumeric to detect A-F as numbers as well as 0-9 (ie, hex)?
Youre better off doing this:

VB.NET:
Dim [B]address [/B]as Long
If Long.TryParse(string, HexNumber, Nothing, [B]address[/B]) Then
  'parsing worked, address now contains the result
Else
  'parsing failed. Maybe the input contains bad characters or is not a number
EndIf

It solves your A-F problem and is more robust than what you had
 
Hmm...my apologies for disappearing, and now for bringing back a dead thread, but I was toying with IsNumeric, and came up with this:

Dim test As String = "10f4"

Dim returnValue As Boolean

returnValue = IsNumeric("&H" & test)

If returnValue = True Then
MessageBox.Show("true")

ElseIf returnValue = False Then
MessageBox.Show("false")

End If

...which works quite well, as far as I can see.
 
Probably not, but it's simpler, more easy for others to read, and probably won't make enough difference in efficiency to be noticeable to the human eye.

Perchance, do you know of a way to count the number of characters in a string before a whitespace (and, optimally, after one)? I recall seeing this somewhere, but I can't remember how it was done, or where I found a reference on it...
 
Probably not, but it's simpler, more easy for others to read
Other what? Monkeys?

If someone asked me if this was numeric:
&H10F4

I'd say no. It contains three characters that are not numbers, the &, the H and the F. I'm a C# programmer, my hex numbers look like 0x10F4. I'm japanese, I dont even use the characters &, H or F in my alphabet.
If anything, its more confusing because you rely on IsNumeric's ability to guess that a string is hex, parse it as hex and see if it works out. One of the biggest problems I see on this forum, is code that almost works, but fails due to humans assuming and computers guessing. SQL dates passed as strings, for example.. There's no excuse for the lack of precision. Computers are precise "creatures", they need feeding precisely.

Additionally, while we are on a "it's easy to read" note.. Why would anyone write code that declares a boolean unnecessarily and then tests it for equality twice, to another boolean? A boolean is already a boolean, you dont need to equate it to another boolean to see if its a boolean:

VB.NET:
boolean = IsEasyToRead()
If boolean = true Then
ElseIf boolean = False Then
End If

What is easy to read about that? It's wordy, disjointed and nothing like any spoken/thinking language in the world.

What's hard about this?
VB.NET:
If IsEasyToRead() Then
Else
EndIf


VB.NET:
If Weather.IsRaining And Umbrella.IsBroken Then
  YouGetWet()
Else
  YouStayDry
EndIf


and probably won't make enough difference in efficiency to be noticeable to the human eye.
IsNumeric is a legacy function. It should be burned. :)

Perchance, do you know of a way to count the number of characters in a string before a whitespace (and, optimally, after one)? I recall seeing this somewhere, but I can't remember how it was done, or where I found a reference on it...

Any whitespace? Split it on a regex \s, limit 1, and get the length:

New Regex("\s").Split("abc def", 1).Length


Can also use classic string split, but you'll have to program every split character yourself
 
Back
Top