6 Replies - 8111 Views - Last Post: 30 June 2009 - 05:50 AM Rate Topic: -----

#1 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

vbOk & vbCancel button choices

Post icon  Posted 23 June 2009 - 01:00 AM

 Private Sub cmdSave_Click()
	Dim Answer As VbMsgBoxResult
	
	If lstYours.ListCount = -0 Then
		MsgBox "Cannot save or send as you have nothing in your list.", vbOKOnly + vbExclamation, "Sorry!"
	Else
		Answer = "InputBox2"
		YourFile = InputBox2("Please enter your name:" & vbCrLf & "Thanks!" & vbCrLf & "This will help me determine who's list I am looking at.", "FileName", "EnterNameHere")
		If InputBox2 = vbOK Then
		
		Dim NextItem As Long
		Open "E:\" & YourFile & ".txt" For Append As #1
			' Loop through the items in the listbox
			For NextItem = 0 To lstYours.ListCount - 1
				' Write to the file the item text
				Print #1, lstYours.List(NextItem)
			Next
		Close #1
	
		' Log into the E-Mail server
		EMailSession.SignOn
		EMailMessage.SessionID = EMailSession.SessionID
		' Create the Message
		EMailMessage.Compose
		EMailMessage.RecipAddress = "blah@hotmail.com"
		EMailMessage.RecipDisplayName = "freddy"
		EMailMessage.MsgSubject = "Here is " & YourFile & "'s list they sent."
		EMailMessage.MsgNoteText = "Hello Freddy, here is my list." & vbCrLf & "Talk Soon!!"
		EMailMessage.AttachmentPathName = "E:\" & YourFile & ".txt"
		' Send the Message
		EMailMessage.Send
		' Log Off the E-Mail Server
		EMailSession.SignOff
	
		MsgBox "Your list has been sent to the Programmer (freddy)." & vbCrLf & "Thankyou!", vbOKOnly + vbExclamation, "E-Mail Sent!"
	Else
		MsgBox "You Canceled", vbOKOnly, "Canceled"
		End If
		
	End If
	

End Sub



Okay, from the code above what i am trying to do is tell the program that if the user clicks cancel in the inputbox it tells them that they canceled the operation and will not send the e-mail.
Problem is ... cannot work it out. any help is always appreciated.


Thanks.

P.S - i need the YourFile in front of the inputbox as that is a global string used throughout the program.
I am using VB6

This post has been edited by PNJLj: 23 June 2009 - 01:02 AM


Is This A Good Question/Topic? 0
  • +

Replies To: vbOk & vbCancel button choices

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: vbOk & vbCancel button choices

Posted 23 June 2009 - 01:38 AM

i dont see any problems what errors you get
Was This Post Helpful? 0
  • +
  • -

#3 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

Re: vbOk & vbCancel button choices

Posted 23 June 2009 - 03:32 AM

View PostNoBrain, on 23 Jun, 2009 - 12:38 AM, said:

i dont see any problems what errors you get


Compile error - Sub or Function not defined

when it gets to the first Inputbox2 code.

just editeded it a little ...
 YourFile = InputBox2 = InputBox("Please enter your name:" & vbCrLf & "Thanks!" & vbCrLf & "This will help me determine who's list I am looking at.", "FileName", "EnterNameHere") 


Now all it does is always cancels. i cannot do okay, when i do i get my msgbox from the else section.

This post has been edited by PNJLj: 23 June 2009 - 03:38 AM

Was This Post Helpful? 0
  • +
  • -

#4 Cookiesliyr  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 136
  • Joined: 16-May 09

Re: vbOk & vbCancel button choices

Posted 23 June 2009 - 04:24 AM

u can do this to know what the user clicked

MsgButton = Msgbox ("Blah blah", vbokcancel + vbExclamation, "whatever")
if msgbutton = VBok then 
' whatever u wanna do 
else if msgbutton = VBCancel then
' u can use else here too
end if 



will as u can see the msgButton would be variant type so there might be another way to do it like in C++ u can do it as int which is much lighter but as long as u won't declare allot of variant types it is ok

Note: the code might have stupid mistake cause it is not tested XD my pc is too far from here but i am sure u can handle these mistakes

This post has been edited by Cookiesliyr: 23 June 2009 - 04:24 AM

Was This Post Helpful? 0
  • +
  • -

#5 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: vbOk & vbCancel button choices

Posted 23 June 2009 - 05:31 AM

An inputbox returns a string so your Answer variable should either equal a vbNullString ("") or it should have a string contained within. So...
Answer = InputBox(...

If Answer = vbNullString Then
  'either user pressed cancel or user did not enter anything
Else
  'user entered something...
End If


However, since you enter a default value then perhaps the code should be ammended to...
Answer = InputBox(...

If Answer = vbNullString Then
  'user pressed cancel 
ElseIf Answer = "EnterNameHere" then
  'user just pressed ok and did not enter name
else
  'user entered something...
End If




Good Luck
Was This Post Helpful? 0
  • +
  • -

#6 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

Re: vbOk & vbCancel button choices

Posted 29 June 2009 - 11:24 PM

Private Sub cmdSave_Click()
	
	If lstYours.ListCount = -0 Then
		MsgBox "Cannot save or send as you have nothing in your list.", vbOKOnly + vbExclamation, "Sorry!"
	Else
		
		YourFile = InputBox("Please enter your name:" & vbCrLf & "Thanks!" & vbCrLf & "This will help me determine who's list I am looking at.", "FileName", "EnterNameHere")
		
		Select Case YourFile
		Case YourFile = ""
			MsgBox "Canceling", vbOKOnly, "Cancel!"
		Case YourFile = "EnterNameHere"
			MsgBox "Canceling", vbOKOnly, "Cancel!"
		Case Else
		
		Dim NextItem As Long
		Open "E:\" & YourFile & ".txt" For Append As #1
			' Loop through the items in the listbox
			For NextItem = 0 To lstYours.ListCount - 1
				' Write to the file the item text
				Print #1, lstYours.List(NextItem)
			Next
		Close #1
	
		' Log into the E-Mail server
		EMailSession.SignOn
		EMailMessage.SessionID = EMailSession.SessionID
		' Create the Message
		EMailMessage.Compose
		EMailMessage.RecipAddress = "j@hotmail.com"
		EMailMessage.RecipDisplayName = "l"
		EMailMessage.MsgSubject = "Here is " & YourFile & "'s list they sent."
		EMailMessage.MsgNoteText = "Hello l, here is my list." & vbCrLf & "Talk Soon!!"
		EMailMessage.AttachmentPathName = "E:\" & YourFile & ".txt"
		' Send the Message
		EMailMessage.Send
		' Log Off the E-Mail Server
		EMailSession.SignOff
		
		MsgBox "Your list has been sent to the Programmer (l)." & vbCrLf & "Thankyou!", vbOKOnly + vbExclamation, "E-Mail Sent!"
		
		End Select
	End If
	

End Sub



Okay, non of any of what you said worked so i thought i would try case select.
haveing difficulties thoe.
Was This Post Helpful? 0
  • +
  • -

#7 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: vbOk & vbCancel button choices

Posted 30 June 2009 - 05:50 AM

Works for me...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1