?
Solved

string manipulation from text box input

Posted on 2003-03-25
6
Medium Priority
?
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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
Course of the Month14 days, 10 hours left to enroll

771 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