Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

string manipulation from text box input

Posted on 2003-03-25
6
Medium Priority
?
294 Views
Last Modified: 2010-04-07
i want a simple form that allows me to take say 4 labels a text box and a button.
If you enter "name" into the text box and click the button label1.cap = "n" label2.cap = "a" label3.cap = "m" and label4.cap = "e"

Please tell me how i can go about this. My problem is that i keep getting errors when i try to set an array equal to a text box or any string. In c++ you can set a char array equal to user input. i want to do this in VB.
0
Comment
Question by:seanreynolds
6 Comments
 
LVL 4

Expert Comment

by:CareyJ
ID: 8207432

Private Sub Command1_Click()
    Label1.Caption = Mid(Text1.Text, 1, 1)
    Label2.Caption = Mid(Text1.Text, 2, 1)
    Label3.Caption = Mid(Text1.Text, 3, 1)
    Label4.Caption = Mid(Text1.Text, 4, 1)
End Sub
0
 
LVL 1

Accepted Solution

by:
robertlees earned 80 total points
ID: 8207439
Create a textbox, a command button and one label. Give the label an index property of 0.

Sub Command1_click()
   dim n as integer

   'remove labels
   for n = label1.ubound to 1 step -1
      unload label1(n)
   next n

   for n=1 to len(text1.text)
      if n>1 then
         load label1(n)
         label1(n).top = label1(0).top
         label1(n).left = label1(n-1).left+label1(n-1).width
         label1(n).visible=true
      end if
      label1(n).caption = mid(text1.text,n,1)
   next n
end sub

This places the label array side-by-side. You can play with the .top and .left statements as required.

Note that the first label is already there - you only have to create the extra labels, and they are positioned with respect to the first label.
0
 

Expert Comment

by:AlbertZee
ID: 8207779
yes sean,

 from my experience to set the array you would use

 dim myArrayName (0 To 10)

 to declare an array of size 10. One problem I encountered with VB is dynamically setting the size of the array at run-time - good luck!!
 
 ...you don't actually need an array though. I thought I'd used Arrays in my last VB project about 10 times - just checked and I can't find 1! Try this - re-create your labels in a control array (draw the first one then copy and paste the others accepting to enter them into a control array), then insert this code into MyButtonName_Click() sub:-
 
 for x = 0 To Len(txtMyTextName.Text)
 
  myLabelName(x).Caption = Mid(txtMyTextName.Text, x, 1)

 Next x

That should sort you out
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Expert Comment

by:vbwizardry
ID: 8208127
I think what you looking for is this:
Dim bytArray() As Byte ' Create byte array same as creating character array in c++
    ' now the key here is that string in vb are in Unicode format so this function will conver them to regular ascii format
    bytArray = StrConv(txt.Text, vbFromUnicode)

Here you go you got your array of characters ;)
Best Regards
0
 

Expert Comment

by:CleanupPing
ID: 8531599
Hi seanreynolds,
This old question (QID 20563150) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9441045
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Accept robertlees's comment as Answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question