Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redim usage

Status
Not open for further replies.

AlexRezid

Programmer
Jul 17, 2003
27
FR
Hi all

I jsut want to redim a string (Mystring) to a table of char (ie : string(0 to Len(Mystring)))

How can I do that ?

Thanks

Alex
 
I think this is what you mean, probably better ways but this is simple, maybe it will help you ?

Dim mystring As String
mystring = "ABC"

Dim MyTable() As String
Dim x As Long

ReDim MyTable(0 To (Len(mystring) - 1))

For x = 0 To Len(mystring) - 1
MyTable(x) = Mid(mystring, x + 1, 1)
Next
 
Thanks SonOf...

Now, I've another problem...

I want to compare each char of my string to the return (\n) char, but I don't know how to write this char in VB...

Because if I write '\n' it tells me an error and if I write "\n" it compares with the string that is write by this two char...

Thanks

Alex
 
To check for a carriage return match the character to vbCr, however if /n equates to new line it could actually be two consecutive characters in the string vbCr followed by vbLf

Again not the only way but is simple, easy to read or extend to other characters

Select Case mycharacter
Case vbCr
'code here if return (13)
Case vbLf
'code here if linefeed (10)
Case "A","a"
'for example code here if an A
Case Else
'code for other characters
End Select
 
Thanks for all SonOF...

I finally did it differently

Here is my code to count the number of lines


Code:
Dim Occ As Integer

Public Function ScanLine(s)
    Dim LengthofLine
    Dim checking
    Dim theLine
    Dim Tmp
    
    Occ = 1
    Tmp = 0
    theLine = s
    LengthofLine = Len(theLine)
    
    For x = 1 To LengthofLine
        checking = Mid(theLine, x, 1)
        If Tmp >
85
Code:
 Then
            Occ = Occ + 1
            Tmp = 0
        End If
        If checking = Chr$(13) Then
            Occ = Occ + 1
            Tmp = 0
        Else
            Tmp = Tmp + 1
        End If
    Next x
End Function

You have to adapt the number in red (number of char per lines)

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top