Jump to content

Inputs first letter to capital


Timppa
 Share

Recommended Posts

Hello! In my program there is a ListView that lists names like this:

$liNameList = GUICtrlCreateListView("Name", 368, 176, 217, 84)

Func AddNames()

    GUICtrlCreateListViewItem(GUICtrlRead($inAddName), $liNameList)
    GUICtrlSetData($inAddName,"")

EndFunc

Okay so that is simple one, just a ListView which adds names to list once you press $bAdd button, it adds $inAddName text inside of the ListView.

The problem is now that I want the first letter to be capital, not everything.

I tried to add this between those GuiCtrlCreateListViewItem and GuiCtrlSetData:

StringUpper(GUICtrlRead($inAddName))

But nothing happened. Then I searched from forums and if I understood correctly, it will make every letter capital, but I want only the first letter to be capital.

Then I face one more problem:

http://imgur.com/AtgjFjG

I want to make the name area wider than it is, is there way to make it wider at the starting of program instead of manually moving?

The upper image means that the area should be that wide as the program opens, and not like in the lower picture (as it appears now like that).

And the third problem (however I haven't googled this yet):

You can input blank inputs in it and it will add the blank item to list; I want to disable this (so If GuiCtrlRead($inAddName) = 0 (?) Then > Show message that you need to type something)

And also, you cannot enter twice the same name (Like two Harry's cannot be in the list)

 

Thanks in advance! And of course I try to somehow solve these by myself but now nothing appears in my mind. And yes, I have read helpfile.

Edited by Timppa
typo
Link to comment
Share on other sites

  • Moderators

Timppa,

- 1. Read the input content into a variable, split off the first character with StringLeft & StringTrimLeft, uppercase the first character and then recombine before adding to the ListView.

- 2. You can set the column width using _GUICtrlListView_SetColumnWidth.

- 3. To prevent adding blanks you will need to check that the input contains a string (you were close):

If GuiCtrlRead($inAddName) = ""

- 4. To prevent adding a duplicate name, search the ListView for the new name using _GUICtrlListView_FindText before adding it.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Allright thanks for the reply and help, Melba23!

By far I have done this:

Func AddNames()

If GuiCtrlRead($inAddName) = "" Then
   MsgBox(0,"","You did not enter a name.")
Else
   Local $ReplaceLetter

   $ReplaceLetter = StringTrimLeft(GuiCtrlRead($inAddName),1)
   StringUpper($ReplaceLetter)
   ;After this, I have no idea how to replace it?

   If _GUICtrlListView_FindText ( $liNameList, GUICtrlRead($inAddName)) Then
      GUICtrlCreateListViewItem(GUICtrlRead($inAddName), $liNameList)
      StringUpper(GUICtrlRead($inAddName))
      GUICtrlSetData($inAddName,"")
   Else
      MsgBox(0,"","That name exists already!")
      GUICtrlSetData($inAddName,"")
   EndIf
EndIf

EndFunc

Okay, so the things that work for me are the duplicate name and the blank space!

Thanks for that :) Yet I am not sure how to add upper cased letter and the first removed letter from the name together.

Something like SomeAddTogetherFunction?($ReplaceLetter + GUICtrlRead($inAddName))

I have no idea how to add those together, or simply GUICtrlCreateListViewItem($ReplaceLetter + GUICtrlRead($inAddName)) ? But then it would be either Hharry OR harry because that $ReplaceLetter only does delete the letter or?

I am pretty confused right now but is there any command that could be in helpfile to describe how to combine those? :D

Link to comment
Share on other sites

$name = "name"
$newname = StringUpper(StringLeft($name, 1)) & StringTrimLeft($name, 1)
Msgbox(0,"", $newname)

:)

Thank you alot! That is the thing I was looking for :)

Here is the whole script if someone is struggling (like me) and googling for answer:

Func AddNames()

If GuiCtrlRead($inAddName) = "" Then
   MsgBox(0,"","You did not enter a name.")
Else
   Local $RawName = GUICtrlRead($inAddName)
   Local $NewName = StringUpper(StringLeft($RawName, 1)) & StringTrimLeft($RawName, 1)

   If _GUICtrlListView_FindText ( $liNameList, $NewName) Then
      GUICtrlCreateListViewItem(($NewName), $liNameList)
.
      GUICtrlSetData($inAddName,"")
   Else
      MsgBox(0,"","That name exists already!")
      GUICtrlSetData($inAddName,"")
   EndIf
EndIf

EndFunc

 

Edited by Timppa
Link to comment
Share on other sites

Okay wait, I found a problem:

I cannot add duplicate name of the FIRST added name, but if there is

Harry

James

Then I can add infinite amount of James in the list, I tried to add this after If _GuiCtrlListView_FindText

$RawName = Null

$NewName = Null

 

But I think it does not matter if I reset the variables. Should it work if I check $inAddName instead of $NewName?

Link to comment
Share on other sites

  • Moderators

Timppa,

You need to start reading the Help file about the functions we suggest. The return from _GUICtrlListView_FindText is the index of the item in the ListView - so merely using:

If _GUICtrlListView_FindText ( $liNameList, $NewName) Then

will mean that the comparison is True if the item is anywhere other then the first (0) index. You need to check for the error return like this:

If _GUICtrlListView_FindText ( $liNameList, $NewName) = -1 Then

Now you will only add the name if it is not found.

As I said: READ the Help file. Do not just think that code will work as you expect - find out what it actually does.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Developers

Ohh, sorry. I guess I read the helpfile too negligently, but I'll try my best to focus on the text I read in future :)

This case is now solved.

Deja Vue ;)

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

To capitalize the first letter of every word, you can also use the function _StringTitleCase.

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...