Visual Basic Problem

B

Bloodking

Guest
Hello, I'm trying to create a program that takes the first letter of each word and places them into a label. I have a For...Next Loop. This is my code
Code:
Dim Wordcount As Integer
        Dim txtWords As String
        Dim count As Integer
        Dim word As String
        Dim space As Integer
        Dim letter As String
        




        Wordcount = InputBox("Enter how many words there are.")
        txtWords = InputBox("Enter the words.")
        word = txtWords
        letter = word.Substring(0, 1)
        For count = 0 To Wordcount
            space = word.IndexOf(" ")
            word = word.Remove(0, space + 1)
            letter = letter + word.Substring(0, 1)
        Next
        Me.Label1.Text = letter
However, it only gets the first word's first letter and last words' first letter(Example: I type in World of Warcraft it says WW instead of WoW)

Please help!
 
B

Bloodking

Guest
Nah, this is Microsoft Visual Basic, heh, I couldn't find anywhere else to ask this question. =(
 
P

Persen

Guest
Now i don't know VB, but doesn't InputBox tend to return strings? You don't have to cast or something?
EDIT: Ignore that, didn't read below... Thought it didn't work at all...
I'll try and see if i can get a solution...

EDIT 2: Got it... Kinda different approach, I coded in PHP because it could be called my native programming language, but i gonna give you in psuedo code:

Code:
bool flag = false;
str char
str chars
str input
int i
// do whatever to get input

for(i = 0;i <= strlen(input); i++) { //strlen is whatever that get string length as int
	char = substr(input, i, 1); //substing of input, start at i, get one char (prolly i+1 there)

	if(char  != " ") {
		if(flag) continue;
 		chars = chars + char; //concatentate here, whatever method you use
 		flag = true;
 	}
 	else flag = false;
 }
 
 //There you go... chars variable filled with letters
Any changes suggested DDR?
 

mase

____ ___ ____ __
Reaction score
154
Code:
Dim Wordcount As Integer
        Dim txtWords As String
        Dim count As Integer
        Dim word As String
        Dim space As Integer
        Dim letter As String
        




        Wordcount = InputBox("Enter how many words there are.")
        txtWords = InputBox("Enter the words.")
        word = txtWords
        letter = word.Substring(0, 1)
        For count = 0 To Wordcount
            space = word.IndexOf(" ")
            word = word.Remove(0, space + 1)
            letter = letter + word.Substring(0, 1)
        Next [b]count[/b]
        Label1.[b]Caption[/b] = letter
:) I bolded what you forgot to add and what was wrong.

-Edit- Just a lil something to add. You could do 'letter = letter + UCase(word.Substring(0,1))' to make it a capital acronym :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top