Community discussion forum

Character Array in VB6.0

Tags: vb6 Pakistan
  • 1 year ago

    hi

    this is C++ Code

    Str1[]= {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z};

    what will be its equivaled VB6.0 code because VB deals with string not with characters. I need characters to manipulate in VB6.0

    thanks

    -------------------------------------------------------------------------------------------------------------------------------------- 

     

     

  • 1 year ago

    No quick way.

    You can use Lset to force-copy the contents of variables into other variables, but for strings the target needs to be a user defined type.

     

    here is an alternative example using function and sub to   get and set single letter values from your original string.

    So, instead of      print   str1(6)    you would use    print getbyte(str1,6)

    and instead of  str1(6) = 'F'   you would use          setbyte  str1,"F",6

     

    Private Sub Form_Load()
    Dim fullstr As String
      str1= "abcdefghijklmnopqrstuvwxyz"

      MsgBox getbyte(str1, 25)
      setbyte str1, "H", 25
      MsgBox getbyte(str1, 25)
    End Sub

    Private Function getbyte(s As String, ByVal place As Integer) As String

    If place < Len(s) Then
    place = place + 1
    getbyte = Mid(s, place, 1)
    Else
    getbyte = ""
    End If
    End Function

    Private Sub setbyte(s As String, newchar As String, ByVal place As Integer)
    place = place + 1
    If Len(newchar) = 0 Then Exit Sub
    If place > Len(s) Then Exit Sub
    Mid(s, place, 1) = Left(newchar, 1)
    End Sub

     

  • 1 year ago

    I remember 2 ways: 

    Private Sub Command1_Click()
    Dim ak As Variant, al() As String
      'first way
      ak = Array("a", "b", "c", "d", "e", "f", "g")
      'second way
      al = Split("a,b,c,d,e,f,g", ",")
      'the same result
      MsgBox ak(2) & "," & al(2)
    End Sub

    Maybe this can be of some help Geeked

  • 1 year ago

     Not entirely sure what you want to do, but isnt it also possible to set an upper bound on a string, e.g.

     Dim sCharArray() as String * 1

    This would indicate a character
     

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback