I'm creating a chatbot on Visual Basic 6.
Private Sub GreetingSub()
convo.Text = beconvo & nickname & ": " & Text.Text & vbNewLine & botname &
"Hello! How are you?" & vbNewLine
End Sub
This is a part of my code. So "nickname & ": " & Text.Text" is the user's name and what they wrote in the input box in the actual conversation box. botname & whatever is following that is what the bot replies.
I've tried Set objTextToSpeech = CreateObject("SAPI.spVoice"), however the program freezes and reads the entire conversation box, which is not what i want.
I need the chatbot to only say his reply out loud, not the user's. Any help is appreciated.
I'm trying to output reports. They all follow the same information, just for different managers. I can't seem to get any of the right syntax in to modify the necessary parts (Recordsource, Caption, and 1 field that will contain a set string). I don't know what its asking me and I can get the code to find the next manager name (a recordsource) and cycle through them. I can get the code to output to PDF file no problem. It's the relevant code below that I need to figure out. It's probably completely wrong. I haven't really dealt with reports yet.
DoCmd.OpenReport "rptUsageReportTemplate", acViewReport
Reports("rptUsageReportTemplate").RecordSource = MngrUsgRptStr
Reports("rptUsageReportTemplate").Caption = MngrName & "'s " & Mnth & " Usage Report"
Reports("rptUsageReportTemplate").Controls("fldManagerHeader") = MngrName & "'s " & Mnth & " Usage Report"
Reports("rptUsageReportTemplate").Requery
DoCmd.Close acReport, "rptUsageReportTemplate", acSaveYes
The "docmd.openreport" Is in there because i couldn't stop getting the error 2451 - The report name [...] you entered is misspelled or refers to a report that isn't open or doesn't exist." I know it exists and I know it's spelled correctly. So it must be an open thing. If I can get Access to output reports behind the scenes without needing to see the report open and close, that would be great.
In short what I want is for the Report I saved to be a template and just update the values a bunch of times and save it to file.
Assuming that you have a "Managers" Table or similar (tblManagersOrSuch) the following untested sub should get you going...
Sub DoManagersReport(Mnth As Integer)
Dim rsManagers As DAO.Recordset
Set rsManagers = CurrentDb.OpenRecordset("tblManagersOrSuch")
If Not rsManagers.EOF Then
rsManagers.MoveFirst
Do Until rsManagers.EOF
DoCmd.OpenReport "rptUsageReportTemplate", acViewPreview, , , acHidden
Reports("rptUsageReportTemplate").Caption = rsManagers!ManagerID & "'s " & Mnth & " Usage Report"
Reports("rptUsageReportTemplate").Controls("fldManagerHeader") = rsManagers!ManagerID & "'s " & Mnth & " Usage Report"
Reports("rptUsageReportTemplate").RecordSource = "Select * from MngrUsgRptStr Where ManagerID = " & rsManagers!ManagerID
DoEvents
Reports("rptUsageReportTemplate").Visible = True
DoCmd.OutputTo acOutputReport, "rptUsageReportTemplate", acFormatPDF, "C:\" & rsManagers!ManagerID & " " & Mnth & " Usage Report.pdf"
DoEvents
DoCmd.Close acReport, "rptUsageReportTemplate"
Loop
End If
'add error handling
End Sub
Note that setting the RecordSource forces a requery so you do not require that.
I would also suggest adding a fileSaveAs function to determine the save folder...
Any ideas why I am getting an "Enter Parameter Value" input box when running this code?
Private Sub cmdPrint_Click()
Dim str As String
On Error GoTo ErrHandler
If IsNull(Me.Combo_1) Then
MsgBox "Can't print an unsaved record", _
vbOKOnly, "Error"
Exit Sub
End If
str = "Combo_1 = '" & Me!Combo_1 & "'"
Debug.Print str
DoCmd.OpenReport "rptBarCodeLabels(2)", acViewPreview, , str
Exit Sub
ErrHandler:
MsgBox Err.Number & ": " _
& Err.Description, vbOKOnly, "Error"
End Sub
Edit: The button is being used to print a label of what's currently selected in Combo_1. Once the print button has been clicked, I wanted it to display the single record I chose in the label report I have it referencing. I am using Access 2003 if that means anything.
If a field name in a query contains punctuation (Combo_1), you should enclose in brackets, like so:
str = "[Combo_1] = '" & Me!Combo_1 & "'"
The Report is expecting a parameter, but not getting it because it's not being passed through in the correct manner.
I've found a solution by using some coding that was provided here: http://www.techrepublic.com/article/how-to-print-one-or-more-labels-for-a-single-access-record/
What fixed the error was most likely creating a temporary table and temporary report.
I am designing a vba userform for excel 2013, in which I use English and Persian text, the problem is when I use a mix of both languages in a msgBox the bits of text come out in the wrong order, the number is supposed to be displayed at the end. here is the code:
Private Sub CommandButton1_Click()
MsgBox "نام" & " - " & "نام" & " - " & "VF" & " - " & 52 & " ." _
, 1 + 1048576 + 524288, "نام برگه"
End Sub
The parts in double quotes and the number are supposed to come from listBoxes.(I just replaced them here with examples, the code behaves the same)
I tried spacing the bits out(works in windows), rearranging the bits and changing msgBox's alignment and reading order, but the result was the same. How to fix this thing?
Could you put all the persian into a string. Have the message box output the string and then have the message box output the numbers?
So it would be something like
aString = ListBox1.value & "-" & listbox2.Value ....
msgbox aString & 52 etc...
Hello everyone i put together this neat little script that quiz's the knowledge of the user on there Star Trek knowledge the script executes perfectly, but when hitting either OK, Cancel or X the questions are still answered as correct. I do know i need a vbCancel set in there somewhere but not sure about how to add it to the script.
'***********************************************************************
'Script Name: StarTrekQuiz.vbs
'Author: CharlesP
'Created: 03/31/15
'Description: This script creates a Star Trek Quiz game.
'***********************************************************************
'Perform script initialization activities
Option Explicit
Dim intPlayGame, strSplashImage, intNumberCorrect, strFederationRank
Dim objFsoObject, objQuestionDict, strAnswer, strQuestion
Const cTitlebarMsg = "The Star Trek Quiz Game"
Set objQuestionDict = CreateObject("Scripting.Dictionary")
objQuestionDict.Add "What was the Science Officer's name in the original Star Trek series?", "spock"
objQuestionDict.Add "What Star Trek villain appeared in both the original series and a Star Trek movie?", "khan"
objQuestionDict.Add "What was the numeric designation of Voyager's on-board Borg?", "7"
objQuestionDict.Add "Name the only Star Trek character to regularly appear on two series and at least two Star Trek movies?",
"worf"
objQuestionDict.Add "What is the last name of your favorite Captain?", "kirk picard sisco janeway archer"
objQuestionDict.Add "Who directed the first Star Trek movie?", "Robert Wise"
objQuestionDict.Add "In what Star Trek TOS episode did the tribbles FIRST appear?", "The Trouble With Tribbles"
objQuestionDict.Add "In what episode of Star Trek TNG did the Enterprise transport samples of Plasma Plague for medical
research?", "The Child"
objQuestionDict.Add "Who voices the computer in TNG?", "Majel Barrett"
objQuestionDict.Add "In TOS ~The Ultimate Computer~ who was the captain of the U.S.S. Excalibur?", "Captain Harris"
'Start the user's score at zero
intNumberCorrect = 0
'Display the splash screen and ask the user if he or she wants to play
strSplashImage = space(11) & "********" & vbCrLf & _
" ******************" & space(20) & "**************************" & _
space(15) & vbCrLf & "*" & space(30) & "*" & space(18) & _
"**" & space(39) & "*" & vbCrLf & " ******************" & _
space(20) & "*************************" & vbCrLf & space(31) & _
"******" & space(26) & "***" & vbCrLf & _
space(34) & "******" & space(22) & "***" & vbCrLf & _
space(37) & "******" & space(17) & "***" & vbCrLf & _
space(26) & " ****************************" & vbCrLf & _
space(26) & "*******************************" & vbCrLf & _
space(26) & "******************************" & vbCrLf & _
space(26) & " ****************************" & vbCrLf & vbCrLf & vbCrLf & _
"Would you like to boldly go where no one has gone before?"
'Ask the user to play
intPlayGame = MsgBox(strSplashImage, 36, cTitlebarMsg)
If intPlayGame = vbYes Then 'User elected to play the game
For Each strQuestion In objQuestionDict
strAnswer = InputBox(strQuestion, cTitlebarMsg)
If Trim(strAnswer) <> "" Then
If Instr(strAnswer, objQuestionDict(strQuestion)) Or Instr(objQuestionDict(strQuestion), strAnswer) Then
MsgBox "Correct"
intNumberCorrect = intNumberCorrect + 1
Else
MsgBox "Nice try. The answer I was looking for was " & objQuestionDict(strQuestion)
End If
End If
Next
Select Case intNumberCorrect
'User got 10 of 10 answers right
Case 10 : strFederationRank = "Fleet Admiral"
'User got 9 of 10 answers right
Case 9 : strFederationRank = "Admiral"
'User got 8 of 9 answers right
Case 8 : strFederationRank = "Vice Admiral"
'User got 7 of 8 answers right
Case 7 : strFederationRank = "Rear Admiral-Upper Hall"
'User got 6 of 7 answers right
Case 6 : strFederationRank = "Rear Admiral-Lower Hall"
'User got 5 of 5 answers right
Case 5 : strFederationRank = "Captain"
'User got 4 of 5 answers right
Case 4 : strFederationRank = "Commander"
'User got 3 of 5 answers right
Case 3 : strFederationRank = "Lieutenant-Commander"
'User got 2 of 5 answers right
Case 2 : strFederationRank = "Lieutenant"
'User got 1 of 5 answers right
Case 1 : strFederationRank = "Lieutenant Junior Grade"
'User did not get any answers right
Case 0 : strFederationRank = "Ensign"
End Select
MsgBox "You answered " & intNumberCorrect & " out of 10 correct." & _
vbCrLf & vbCrLf & "Your Star Fleet rank is : " & _
strFederationRank, , cTitlebarMsg
Else 'User doesn't want to play
MsgBox "Thank you for taking the Star Trek Quiz" & _
vbCrLf & vbCrLf & "Live long and prosper!", , cTitlebarMsg
WScript.Quit()
End If
Any help would be much appreciated thank you all in advance.
Unlike MsgBox function or Popup method, InputBox function has no vbCancel option.
If the user clicks OK or presses ENTER, the
InputBox function returns whatever is in the text box. If the user
clicks Cancel or ×, the function returns a
zero-length string ("").
Strictly speaking, above MSDN quotation is not right. If the user
clicks Cancel or × button or presses Esc key, the function returns Empty value (the same as if a variable is uninitialized.
Next code snippet could help.
' Ask the user to play
intPlayGame = MsgBox(strSplashImage, vbYesNo + vbQuestion, cTitlebarMsg)
Dim WshShell 'prepare for POPUP method
Set WshShell = WScript.CreateObject("WScript.Shell")
If intPlayGame = vbYes Then 'User elected to play the game
For Each strQuestion In objQuestionDict
strAnswer = InputBox(strQuestion, cTitlebarMsg)
If VarType( strAnswer)=0 Then
intPlayGame = WshShell.Popup( _
"Cancel pressed or window closed. Continue?", 7, _
cTitlebarMsg, vbYesNo + vbQuestion)
If not intPlayGame = vbYes Then Wscript.Quit
strAnswer=""
End If
if strAnswer="" Then strAnswer="???"
If Instr(1, strAnswer, objQuestionDict(strQuestion), vbTextCompare) _
Or Instr(1, objQuestionDict(strQuestion), strAnswer, vbTextCompare) Then
MsgBox "Correct"
intNumberCorrect = intNumberCorrect + 1
Else
MsgBox strAnswer & " Nice try. The answer I was looking for was " & objQuestionDict(strQuestion)
End If
Next
Select Case intNumberCorrect
Predefined MsgBox / Popup Constants
' Button Type
' vbOKOnly 0 Display OK button only.
' vbOKCancel 1 Display OK and Cancel buttons.
' vbAbortRetryIgnore 2 Display Abort, Retry, and Ignore buttons.
' vbYesNoCancel 3 Display Yes, No, and Cancel buttons.
' vbYesNo 4 Display Yes and No buttons.
' vbRetryCancel 5 Display Retry and Cancel buttons.
' Icon Type
' vbCritical 16 Display Critical Message icon.
' vbQuestion 32 Display Warning Query icon.
' vbExclamation 48 Display Warning Message icon.
' vbInformation 64 Display Information Message icon.
' Default Button: MsgBox Function only
' vbDefaultButton1 0 First button is the default.
' vbDefaultButton2 256 Second button is the default.
' vbDefaultButton3 512 Third button is the default.
' vbDefaultButton4 768 Fourth button is the default.
' Modality of the box: MsgBox Function only
' vbApplicationModal 0 Application modal. The user must respond to the message box before continuing work in the current application.
' vbSystemModal 4096 System modal. On Win16 systems, all applications are suspended until the user responds to the message box. On Win32 systems, this constant provides an application modal message box that always remains on top of any other programs you may have running.
' Return Value
' vbOK 1 OK
' vbCancel 2 Cancel
' vbAbort 3 Abort
' vbRetry 4 Retry
' vbIgnore 5 Ignore
' vbYes 6 Yes
' vbNo 7 No
' vbTrue -1 nSecondsToWait elapsed, the user did not click a button before
'
Edit:
#Ekkehard.Horner is right as CStr(VarType(strAnswer)) & TypeName(strAnswer) returns 0Empty if clicked Cancel or × in response to an InputBox. My resource: MSDN VBScript language reference.
But it's a faultfinder's quibble only here because by the same MSDN: how expressions are compared: if one expression is Empty and the other is a string, then perform a string comparison, using a zero-length string ("") as the Empty expression.
Thus, If strAnswer = "" ... comparison gives the same result regardless of strAnswer variable
is an empty string "", or
is uninitialized, or is explicitly set to Empty.
However, we could test VarType(strAnswer) and allow a user to correctly terminate the quiz uncomplete (see update in code snippet, used Popup method).
Clicking on cancel returns empty string in Inputbox.
So, check if the answer is "".
For Each strQuestion In objQuestionDict
strAnswer = InputBox(strQuestion, cTitlebarMsg)
If Trim(strAnswer) <> "" Then
If Instr(strAnswer, objQuestionDict(strQuestion)) Or Instr(objQuestionDict(strQuestion), strAnswer) Then
MsgBox "Correct"
intNumberCorrect = intNumberCorrect + 1
Else
MsgBox "Nice try. The answer I was looking for was " & objQuestionDict(strQuestion)
End If
End If
Next