Vb coding..

Locked
kylegoodmaster
Posts: 252
Joined: Fri Feb 15, 2002 3:09 am

Post by kylegoodmaster »


I need the code for how to make a app for the following..


 


To make a name typed into a textbox and display only the initials, and capitalize them. How in the world do I do this...  :confused:


 


 


 


Vb code only plz tkx  :thumbup:


YouWantSome?
Posts: 154
Joined: Sat Apr 20, 2002 9:50 am

Post by YouWantSome? »


I am little rusty but here it is:


 


txt_Name is the name text box, Txt_INitials is the result initials


 


Private Sub GO_Click()


? ?Dim sName


? ?Dim sInitials


? ?Dim integerCharCount   'Thanks to ian :)


? ?


? ?sInitials = ""


? ?sName = Txt_Name.Text


? ?


? ?'---- If there is any text, take first letter ----


? ?


? ?If Len(sName) > 0Then


? ? ? ?sInitials = Left(sName, 1)


? ?End If


? ? ? ?


? ?'---- Loop through name and take letters after a space --


? ?


? ?integerCharCount = 2


? ?


? ?Do While integerCharCount < Len(sName)


? ? ? ?If Mid(sName, integerCharCount - 1, 1) = " " And Mid(sName, integerCharCount, 1) <> " " Then


? ? ? ? ? ?sInitials = sInitials + Mid(sName, integerCharCount, 1)


? ? ? ?End If


? ?Loop


? ? ? ?


? ?Txt_Initials.Text = sInitials


? ? ? ?


End Sub


YouWantSome?
Posts: 154
Joined: Sat Apr 20, 2002 9:50 am

Post by YouWantSome? »


To capitalise use:


 


Txt_Initials.Text = UCase(sInitials)


ianskate
Posts: 80
Joined: Mon Apr 08, 2002 1:33 am

Post by ianskate »

why did you use such awful variables  :confused:  :tongue:

YouWantSome?
Posts: 154
Joined: Sat Apr 20, 2002 9:50 am

Post by YouWantSome? »


why did you use such awful variables ?:confused: ?:tongue:

if you mean sName and sInitials, I use hungarian notation whenever I can, which means the first character(s) of the variable tell you what type it is.


 


s is for String.


 


If you mean txt_Name, txt is to show it is a text box.


 


I code in a few languages and use different standards, I haven't used VB for a while.


 


I think they are meaningful, they tell me what type of variable they are, and the names tell me what they are.


 


What would you have used???


ianskate
Posts: 80
Joined: Mon Apr 08, 2002 1:33 am

Post by ianskate »


hehe, that arent bad if you know what they mean... now that i know what i mean, they arent so bad... but i wouldve written them out like stringName, or inputtedText, just something that any idiot (such as i) could understand without having to go through all the code and figure out what was being used for what. the one that got me the most was this, "ia". I'm assuming its a counter, but ack!  :D


 


anyway, it works well, so it doesn't matter.  :)


YouWantSome?
Posts: 154
Joined: Sat Apr 20, 2002 9:50 am

Post by YouWantSome? »


hehe, that arent bad if you know what they mean... now that i know what i mean, they arent so bad... but i wouldve written them out like stringName, or inputtedText, just something that any idiot (such as i) could understand without having to go through all the code and figure out what was being used for what. the one that got me the most was this, "ia". I'm assuming its a counter, but ack! ?:D

 


anyway, it works well, so it doesn't matter. ?:)



yeah ia is a bad habit I picked up from my C days.


 


It is suppose to mean i as in integer, the a is because I use a lot of temporary counters and call them ia, ib, ic.


 


Yeah I agree that is shit, it should have been iCharCount or something like that.


 


I have a lot of bad habits, because most of what i know with languages is self taught.


 


What are they teaching schools these days? stringName is good, in C++ they recommend szName, where sz stands for "null terminated string".


 


Ahh well, the harder my code is to read, the more times they have to call me back to modify it hehe "I AM IRREPLACEABLE"


 


lol


 


/me modifies code


ianskate
Posts: 80
Joined: Mon Apr 08, 2002 1:33 am

Post by ianskate »


:eek:


 


heh, well in the java class im taking, the professor stressed using variables involving a full name to show what it really does, and the same goes for functions, or methods, whatever you want to call them...


names such as getActionWindow, real words to help remember what its for... but thats java, and java sucks anus. :thumbdown:


Captain Pissflaps
Posts: 75
Joined: Tue May 07, 2002 5:24 pm

Post by Captain Pissflaps »

Same with C++ though, always best to make your variable as 'obvious' as possible - makes it easier when you look through some code you wrote weeks ago.

Locked