From: Mike Williams on
"Bill Betournay" <bill(a)REMOVEdatapacks.com> wrote in message
news:%23wndw1CyKHA.5292(a)TK2MSFTNGP06.phx.gbl...

> And Mike Williams, that example you provided was great in the
> sense that you seem to understand. Problem is the ability to capture
> the carriage return. That's my issue. You example takes my list and
> rips it through a bunch of loops but returns the same list. In fact the
> string example below was the result of your example.

Well, the thing is, your original post did not make it very clear what you
actually wanted to do, and it certainly did not describe what you wanted in
the way you have just done in this post, in fact it was almost the opposite
of it. In your original post (the one to which I responded) you said that
you had a string like this: "1 1.1 1.2 1.3 1.4 1.5 1.6" and you said that
sometimes it might have more than one carriage return like it is shown in
your example. However, your example (the numbers all in one line" as shown
above) did not have any carriage returns at all . . . it in fact had spaces.
You then said that you "wanted to separate it out like this":

1
1.1
1.2
.. . . etc

So, your display of the starting string and the result you wanted clearly
showed a starting sring with spaces and a result with carriage returns, or a
series of individual values, quite the opposite of what you have just asked
for in this new message of yours. That's why in the preface to my response I
posed the question, "You mean you have more than one space?", indicating
that I had assumed exactly what I have said above (because of the way you
displayed your strings) and that your mention of more than one carriage
return was a mistake and you actually meant more than one space. Anyway,
that's what the code in my response was intended to do. It was intended to
start off with a string containing spaces and to strip out those spaces and
return the individual values (as individual strings) in an array.

However, from your most recent response, it is now clear (whereas it was not
before) that you are actually starting starting off with a string that
contains what you personally believe to be carriage returns and that you
want to strip out all those carriage returns so that you return a single
string containing all the individual values "all on one line", so to speak.
Such a task is also very easy to do, although I'm not at the moment sure
whether you are looking for some "finished code" that just does the job for
you or whether you are looking for help so that you can learn how to do it
yourself in such a way that you will fully understand it. On the assumption
that you want the latter I will resist the temptation to post some working
code (I've already been told off for that!) and I will just give you one or
two pointers. The very first pointer, and by far the most important one, is
to not actually show you any method by which you can accomplish the task
(although you have already been shown most of them) but rather to show you
how to establish what task it is that you actually need to perform. That
might sound a little odd to you, but if you want to do any job then the
first and most important thing is to analyse that job and to determine
exactly what it is. The very first part of converting one thing into
something else is to determine for absolute certainty what it is you are
actually starting with.

You haven't said where you are getting your original string from (perhaps
loading it in from a file or something) but I presume that you are ending up
with it being contained in a standard VB String variable. So, to start you
off, here is some code that generates a starting string much like the
starting string you have recently described. It builds it into a standard VB
String variable called s1. It then prints that string to the Form so that
you can see what it looks like when printed. It should look like the string
you have described in this latest post of yours. The next job the code does
is to analyze that string in a small loop and display the Ascii code of each
character in a listBox, together with the character each of those Ascii
codes represents (except for non printing characters, where it just displays
the Ascii code). Have a look at the output in the ListBox and you should be
able to see the carriage returns it contains. Each one is actually a pair of
characters, the Ascii code 13 (a carriage return character) followed by the
Ascii code 10 (a line feed character). This pair is commonly known as vbCrLf
in VB.

When you have done the above then edit the code so that you remove the
"string building stuff" and instead do whatever you are currently doing to
place your own string you are starting with into the s1 string variable, and
allow the "Display this string in the LisBox" code to display the details of
your own string. Does it look the same? Are the Ascii codes between the
individual values Chr(13) followed by Chr(10)? Or are they something else?
Post back when yuo have done that, with full details of what you find.

Anyway, the code mentioned is shown below. Paste it into a VB Form
containing one ListBox and one Command Button. Position both of those
controls a little bit away from the left edge of the Form, to allow space
for the stuff that the code will print. Then run the project and click the
button.

By the way, before we go much further into this it would be helpful if you
told us *exactly* what version of Visual Basic you are using.

Mike


Private Sub Command1_Click()
Dim value As Single, s1 As String
Dim n As Long, p As Long, sCheck As String
' first create a test string that looks like
' the string Bill Betournay appears to be
' starting with
value = 8
s1 = s1 & Format(value) & vbCrLf
s1 = s1 & vbCrLf
s1 = s1 & vbCrLf
For value = 8.01 To 8.26 Step 0.01
s1 = s1 & Format(value, "#.00") & vbCrLf
Next value
' print the string to the Form so that
' you can see what it looks like when printed
Me.Cls
Print s1
' now display the individual characters
' of the string in a ListBox, showing
' Ascii codes as well
List1.Clear
For n = 1 To Len(s1)
p = Asc(Mid$(s1, n, 1))
If p > 31 Then
List1.AddItem n & vbTab & Chr$(p) & vbTab & p
Else
List1.AddItem n & vbTab & vbTab & p
End If
Next n
End Sub





From: Henning on
You could just ignore what invalid characters there is. Guess it is fast
enough for not too long strings.

Option Explicit

Dim r As String
Dim s As String

Private Sub Command1_Click()
Dim i As Long
Dim t As String
Dim valid As Boolean

r = ""
valid = False

For i = 1 To Len(s)
t = Mid$(s, i, 1)
Select Case Asc(t)
Case 48 To 57, 46 '0-9 or .
valid = True
r = r + t
Case Else
If valid Then
r = r + ","
valid = False
End If
End Select
Next
r = Left$(r, Len(r) - 1) 'remove last comma
Text1.Text = r
End Sub

Private Sub Form_Load()
s = "8" & vbCrLf & vbCr & vbLf
s = s & "8.1 " & vbLf
s = s & "8.2xz" & vbLf
s = s & "8.3" & vbCrLf
s = s & "8.4 " & "abcd"
s = s & "8.5 " & vbCr
s = s & "8.6 " & vbCrLf
s = s & "8.7" & vbLf
s = s & "8.8 " & vbLf
s = s & "8.9" & vbCrLf
s = s & "8.10" & vbCrLf
s = s & "8.11" & vbCrLf
s = s & "8.12" & vbCrLf
s = s & "8.13" & vbCrLf
s = s & "8.14" & vbCrLf
s = s & "8.15" & vbCrLf
s = s & "8.16" & vbCrLf
s = s & "8.17" & vbCrLf
s = s & "8.18" & vbCrLf
s = s & "8.19" & vbCrLf
s = s & "8.20" & vbCrLf
s = s & "8.21" & vbCrLf
s = s & "8.22" & vbCrLf
s = s & "8.23" & vbCrLf
s = s & "8.24" & vbCrLf
s = s & "8.25" & vbCrLf
s = s & "8.26" & vbCrLf
End Sub

/Henning

"Bill Betournay" <bill(a)REMOVEdatapacks.com> skrev i meddelandet
news:eVyQTYDyKHA.3304(a)TK2MSFTNGP06.phx.gbl...
> Sweet, thank you Helmut.
>
> I think we're on to something. It's 10 not 13.
>
> no, I didn't run those that order. I was only showing you the ones I had
> tried.
>
> I'll get back to ya. this may be the answer.
>
> Bill
>
> "Helmut Meukel" <NoSpam(a)NoProvider.de> wrote in message
> news:O67wrHDyKHA.5364(a)TK2MSFTNGP05.phx.gbl...
>> "Bill Betournay" <bill(a)REMOVEdatapacks.com> schrieb im Newsbeitrag
>> news:%23wndw1CyKHA.5292(a)TK2MSFTNGP06.phx.gbl...
>>> Good Morning guys. Thank you both for your offerings. MikeD, I was
>>> stepping it through building my solution and then discovered the problem
>>> of parsing out the ?? Object ( think it's a carriage return) from the
>>> list. I hope I'm not missing your point.
>>>
>>> And Mike Williams, that example you provided was great in the sense that
>>> you seem to understand. Problem is the ability to capture the carriage
>>> return. That's my issue. You example takes my list and rips it through a
>>> bunch of loops but returns the same list. In fact the string example
>>> below was the result of your example. It's not capturing the stuff
>>> between the numbers either. I don't understand why I can't seem to get
>>> the whatever it is between each set of numbers
>>>
>>> Thank you both and yes, this may have changed a little since my OP
>>> because I've used your examples and learned a little more. :-)
>>>
>>> here's what I've tried
>>>
>>> Replace(myInputStr, vbCr, ",")
>>> Replace(myInputStr, vbCrLf, ",")
>>> Replace(myInputStr, vbCr, ",")
>>> Replace(myInputStr, Chr$(13), ",")
>>> Replace(myInputStr, Chr(13), ",")
>>>
>>> here's an example of a string I have.
>>> "8
>>>
>>>
>>> 8.1
>>> 8.2
>>> 8.3
>>> 8.4
>>> 8.5
>>> 8.6
>>> 8.7
>>> 8.8
>>> 8.9
>>> 8.10
>>> 8.11
>>> 8.12
>>> 8.13
>>> 8.14
>>> 8.15
>>> 8.16
>>> 8.17
>>> 8.18
>>> 8.19
>>> 8.20
>>> 8.21
>>> 8.22
>>> 8.23
>>> 8.24
>>> 8.25
>>> 8.26"
>>>
>>> and ultimately here what I would like
>>> "8,8.1,8.2,8.3,8.4,8.5,8.6,8.7,8.8,8.9,8.10,8.11,8.12,8.13,8.14,8.15,8.16,8.17,8.18,8.19,8.20,8.21,8.22,8.23,8.24,8.25,8.26"
>>>
>>> Does that clear
>>>
>>
>>
>> Bill,
>>
>> What you should have done first place is to check which characters
>> are actually in your string.
>> Something like this:
>> for i =1 to len(teststring)
>> Debug.Print Asc(mid(teststring, i, 1))
>> next
>> Step with F8 through this loop, after a few steps you'll _know_ what
>> to expect, CR, LF, space, or any combination of these. Maybe you'll
>> even find it's no ordinary space but a Chr$(160), which just looks
>> like a space.
>>
>> One comment on your code:
>> did you really run those replace statements in this order?
>> Then you replaced first the CR in any CRLF pair in your string,
>> so the second statement couldn't find CRLF anymore. But you never
>> replaced the remaining LF if there was any CRLF originally!
>>
>> Helmut.
>
>


From: Cor Ligthert[MVP] on
Nobody,

I made today a sample for the VB.Nxt Forum with VB10

It was looking almost like this.

Dim b As String()
Dim a As String
a = "Hello" & vbCrLf & vbCrLf & "World"
a = Strings.Replace(a, " ", " ") 'This can in a for or do while
loop
b = Strings.Split(a, vbCrLf)

In fact is the only thing I really changed for this newsgroup is that in
VB10, I would normally write

Dim a as string = "Hello" & vbCrLf & vbCrLf & "World"

I've at home no VB6 installed, but in my idea does this run in VB6 the same
as in VB10

Cor

"Nobody" <nobody(a)nobody.com> wrote in message
news:uU7NbkDyKHA.5936(a)TK2MSFTNGP04.phx.gbl...
> "Bill Betournay" <bill(a)REMOVEdatapacks.com> wrote in message
> news:%23wndw1CyKHA.5292(a)TK2MSFTNGP06.phx.gbl...
>> I was stepping it through building my solution
>
> Are you using one of the dotnet based versions? Such as VB 2005/2008? If
> so, you are in the wrong group. This group is for VB6 and earlier(VB
> Classic). VB.Net and all dotnet groups have either "dotnet" or "vsnet" in
> the group name. Please use the following group instead:
>
> news://msnews.microsoft.com/microsoft.public.dotnet.languages.vb
>
> MS broke compatibility after VB6, so code for VB6 may not work in
> VB.Net/2005/2008, and in most cases, projects require a rewrite to be
> upgraded or converted. See here for details:
>
> http://en.wikipedia.org/wiki/Visual_Basic_.NET#Criticism
>
>
From: Cor Ligthert[MVP] on
Duh,

I've changed it in the message because it did look to complicated with that
VBCrlF twice.
And now it is rubish, the original was about a txt file.

Let show it this way what I made now in VB10 from it
Dim b As String()
Dim a As String
a = "Hello World"
a = Strings.Replace(a, " ", " ")
b = Strings.Split(a, " ").

Cor

"Cor Ligthert[MVP]" <Notmyfirstname(a)planet.nl> wrote in message
news:#n7C55QyKHA.2644(a)TK2MSFTNGP04.phx.gbl...
> Nobody,
>
> I made today a sample for the VB.Nxt Forum with VB10
>
> It was looking almost like this.
>
> Dim b As String()
> Dim a As String
> a = "Hello" & vbCrLf & vbCrLf & "World"
> a = Strings.Replace(a, " ", " ") 'This can in a for or do while
> loop
> b = Strings.Split(a, vbCrLf)
>
> In fact is the only thing I really changed for this newsgroup is that in
> VB10, I would normally write
>
> Dim a as string = "Hello" & vbCrLf & vbCrLf & "World"
>
> I've at home no VB6 installed, but in my idea does this run in VB6 the
> same as in VB10
>
> Cor
>
> "Nobody" <nobody(a)nobody.com> wrote in message
> news:uU7NbkDyKHA.5936(a)TK2MSFTNGP04.phx.gbl...
>> "Bill Betournay" <bill(a)REMOVEdatapacks.com> wrote in message
>> news:%23wndw1CyKHA.5292(a)TK2MSFTNGP06.phx.gbl...
>>> I was stepping it through building my solution
>>
>> Are you using one of the dotnet based versions? Such as VB 2005/2008? If
>> so, you are in the wrong group. This group is for VB6 and earlier(VB
>> Classic). VB.Net and all dotnet groups have either "dotnet" or "vsnet" in
>> the group name. Please use the following group instead:
>>
>> news://msnews.microsoft.com/microsoft.public.dotnet.languages.vb
>>
>> MS broke compatibility after VB6, so code for VB6 may not work in
>> VB.Net/2005/2008, and in most cases, projects require a rewrite to be
>> upgraded or converted. See here for details:
>>
>> http://en.wikipedia.org/wiki/Visual_Basic_.NET#Criticism
>>
>>
From: Nobody on
"Cor Ligthert[MVP]" <Notmyfirstname(a)planet.nl> wrote in message
news:Ogdvg9QyKHA.4240(a)TK2MSFTNGP06.phx.gbl...
> Duh,
>
> I've changed it in the message because it did look to complicated with
> that VBCrlF twice.
> And now it is rubish, the original was about a txt file.
>
> Let show it this way what I made now in VB10 from it
> Dim b As String()
> Dim a As String
> a = "Hello World"
> a = Strings.Replace(a, " ", " ")
> b = Strings.Split(a, " ").
>
> Cor

"Dim b As String()" line doesn't compile in VB6, and there is no "Strings."
class in VB6. The two languages are too different to make code that works in
both, except in the smallest of cases, and it takes more effort to make code
that works on both, but it wouldn't take the maximum advantage of either
language. Also, giving even one .Nxt answer here is really a bad idea,
another person who is using .Nxt might find an error, or that a certain
construct is not efficient, then the thread would turn into an argument
about what's the best way to do that task in .Nxt, so it becomes exclusively
about .Nxt, which is better served in another group.



First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9
Prev: Combobox Showing Right Justified
Next: Can't make exe