10 Replies - 65024 Views - Last Post: 24 July 2009 - 07:25 AM Rate Topic: -----

#1 antukin_cs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 06-October 07

visual basic 6.0 - upper case and lower case

Posted 11 October 2007 - 04:32 AM

here's a sample code..

Private sub cmdOK_Click()
	  if txtUSERNAME.Text="username" and txtPASSWORD.Text="password" then
		  unload me
		  frmMAIN.Show
	 else
		  msgbox"Error!"
				  txtUSERNAME.Text=""
				  txtPASSWORD.Text=""
				  txtUSERNAME.SetFocus
	end if
	End sub


what code should i use to make the program accept both upper case and lower case text inputs??

This post has been edited by antukin_cs: 11 October 2007 - 04:34 AM


Is This A Good Question/Topic? 0
  • +

Replies To: visual basic 6.0 - upper case and lower case

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1633
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: visual basic 6.0 - upper case and lower case

Posted 11 October 2007 - 04:46 AM

Well to convert to uppercase you would use the UCase function, but with user name and password you want the password to be case sensitive, it doesn't really matter about the user name, that doesn't have to be case sensitive.
Something like this:

Private sub cmdOK_Click()
	  if (UCase(txtUSERNAME.Text) ="USERNAME") and txtPASSWORD.Text="password" then
		  unload me
		  frmMAIN.Show
	 else
		  msgbox"Error!"
				  txtUSERNAME.Text=""
				  txtPASSWORD.Text=""
				  txtUSERNAME.SetFocus
	end if
End sub



Doing it that way, as above with the user name, it doesnt matter is they enter lower or upper case, as you're converting it to uppercase when comparing.

NOTE:It is actually considered best practices to make passwords case sensitive
Was This Post Helpful? 1

#3 antukin_cs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 06-October 07

Re: visual basic 6.0 - upper case and lower case

Posted 11 October 2007 - 05:03 AM

if i want to make the password sensitive as you said..should i write the code this way??


if (UCase(txtUSERNAME.Text) ="USERNAME") and (UCase(xtPASSWORD.Text="PASSWORD")

This post has been edited by antukin_cs: 11 October 2007 - 05:04 AM

Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1633
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: visual basic 6.0 - upper case and lower case

Posted 11 October 2007 - 05:08 AM

Yup, but its a really bad idea to not make the password case sensitive.
Was This Post Helpful? 0
  • +
  • -

#5 antukin_cs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 06-October 07

Re: visual basic 6.0 - upper case and lower case

Posted 11 October 2007 - 05:11 AM

thanks for the help man appreciate it..
Was This Post Helpful? 0
  • +
  • -

#6 tica0419  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 08-October 07

Re: visual basic 6.0 - upper case and lower case

Posted 13 October 2007 - 09:43 PM

View PostPsychoCoder, on 11 Oct, 2007 - 04:46 AM, said:

Well to convert to uppercase you would use the UCase function, but with user name and password you want the password to be case sensitive, it doesn't really matter about the user name, that doesn't have to be case sensitive.
Something like this:

Private sub cmdOK_Click()
	  if (UCase(txtUSERNAME.Text) ="USERNAME") and txtPASSWORD.Text="password" then
		  unload me
		  frmMAIN.Show
	 else
		  msgbox"Error!"
				  txtUSERNAME.Text=""
				  txtPASSWORD.Text=""
				  txtUSERNAME.SetFocus
	end if
End sub



Doing it that way, as above with the user name, it doesnt matter is they enter lower or upper case, as you're converting it to uppercase when comparing.

NOTE:It is actually considered best practices to make passwords case sensitive


can i also use the same code for searching case insensitively in flexgrid? im using VB6.0

what i did is i can search the database which is linked to a flexgrid.. if the record is found, it would highlight that record and other records with the same record name.. but the problem is if I search for "voucher", it will only look for records with "voucher" and skipping "Voucher".. so i kust want wo know if i could also use this code for flexgrid...
Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1633
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: visual basic 6.0 - upper case and lower case

Posted 13 October 2007 - 11:12 PM

You can use it for that, just use

If UCase(SomeGridItem) = UCase("YOurSearchString") Then



and it will find all matches for that word.
Was This Post Helpful? 0
  • +
  • -

#8 tica0419  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 08-October 07

Re: visual basic 6.0 - upper case and lower case

Posted 15 October 2007 - 01:06 AM

View PostPsychoCoder, on 13 Oct, 2007 - 11:12 PM, said:

You can use it for that, just use

If UCase(SomeGridItem) = UCase("YOurSearchString") Then



and it will find all matches for that word.


thanks a lot for the help.. but can you help me where I can insert that code? I tried inserting it after the INSTR condition using "AND" just before "THEN" but nothing happened.. here's my code:


MSFlexGrid1.FillStyle = flexFillRepeat
MSFlexGrid1.Col = 0
MSFlexGrid1.Row = 0
MSFlexGrid1.ColSel = MSFlexGrid1.Cols - 1
MSFlexGrid1.RowSel = MSFlexGrid1.Rows - 1
MSFlexGrid1.CellFontBold = False

	MSFlexGrid1.FillStyle = flexFillSingle
	
	For i = 0 To MSFlexGrid1.Cols - 1
	For j = 1 To MSFlexGrid1.Rows - 1
		
	If InStr(MSFlexGrid1.TextMatrix(j, i), _
	TEXTSEARCH.Text) And _
	(UCase(MSFlexGrid1.TextMatrix(j, i)) = UCase("textsearch.text")) Then

	MSFlexGrid1.Col = i
	MSFlexGrid1.Row = j
	MSFlexGrid1.CellFontBold = True
	MSFlexGrid1.CellBackColor = &H80FFFF
	TEXTSEARCH.SetFocus

	End If
		   
	Next j
	Next i

End Sub 

Was This Post Helpful? 0
  • +
  • -

#9 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1633
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: visual basic 6.0 - upper case and lower case

Posted 15 October 2007 - 01:35 AM

Well you're using InStr incorrectly, when you say InStr(MSFlexGrid1.TextMatrix(j, i),TEXTSEARCH.Text) that isnt a legal statement since InStr doesn't return a boolean value, it returns an integer value:

Quote

InStr Function

Returns the position of the first occurrence of one string within another.

InStr([start, ]string1, string2[, compare])


So you're If statement isnt valid as you're not comparing it to a value, try your if statement like this

If InStr(MSFlexGrid1.TextMatrix(j, i),TEXTSEARCH.Text) > 0 _
And UCase(MSFlexGrid1.TextMatrix(j, i)) = UCase("textsearch.text") Then



What I'm doing there is saying, ok if the occurrence of this string is found in the 2nd string (checking for > 0 and UCase(this) = Ucase(that) then do something.

Do you understand my explanation of that?, hope that makes things a bit clearer for you :)
Was This Post Helpful? 0
  • +
  • -

#10 tica0419  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 08-October 07

Re: visual basic 6.0 - upper case and lower case

Posted 15 October 2007 - 06:00 PM

View PostPsychoCoder, on 15 Oct, 2007 - 01:35 AM, said:

Well you're using InStr incorrectly, when you say InStr(MSFlexGrid1.TextMatrix(j, i),TEXTSEARCH.Text) that isnt a legal statement since InStr doesn't return a boolean value, it returns an integer value:

Quote

InStr Function

Returns the position of the first occurrence of one string within another.

InStr([start, ]string1, string2[, compare])


So you're If statement isnt valid as you're not comparing it to a value, try your if statement like this

If InStr(MSFlexGrid1.TextMatrix(j, i),TEXTSEARCH.Text) > 0 _
And UCase(MSFlexGrid1.TextMatrix(j, i)) = UCase("textsearch.text") Then



What I'm doing there is saying, ok if the occurrence of this string is found in the 2nd string (checking for > 0 and UCase(this) = Ucase(that) then do something.

Do you understand my explanation of that?, hope that makes things a bit clearer for you :)


yup got it.. thanks for the advice.. anyway, the UCase is still not working.. i didnt get any error but it's not doing anyting either..
Was This Post Helpful? 0
  • +
  • -

#11 izok  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-July 09

Re: visual basic 6.0 - upper case and lower case

Posted 24 July 2009 - 07:25 AM

Hi, I have the same problem. I want my search result to show in flex grid, and I don't want it to be case sensitive.

I'm working on a library program.
 Private Sub buttfind_Click()
Dim Bookcode As String
Bookcode = txtbookcode


Dim flag As String
flag = "No"
Dim counter As Integer



counter = 1
BData.MoveFirst
While BData.EOF = False

If BData!Bookcode = txtbookcode Then

Grid1.TextMatrix(counter, 0) = BData!ID
Grid1.TextMatrix(counter, 1) = BData!Bookcode
Grid1.TextMatrix(counter, 2) = BData!AuthorSurname
Grid1.TextMatrix(counter, 3) = BData!AuthorFirstname
Grid1.TextMatrix(counter, 4) = BData!Title
Grid1.TextMatrix(counter, 5) = BData!Publisher
Grid1.TextMatrix(counter, 6) = BData!YearPublished
Grid1.TextMatrix(counter, 7) = BData!Available
Grid1.TextMatrix(counter, 8) = BData!Genre

counter = counter + 1
Grid1.Rows = Grid1.Rows + 1
flag = "yes"
End If
BData.MoveNext
Wend
If flag = "No" Then
MsgBox ("Record not found")
End If

End Sub


I tried using the InStr function, but I'm not sure where to put it. Please advice.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1