What i am trying to do is call functions from a string that I created
The example would be:
genoutput is a string I made to concatenate the function calls when a certain combo box item was selected...
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button2.Click
Select Case ComboBox1.SelectedItem
Case "First Name"
genoutput = genoutput & randomfirstname() & vbTab
Case "Last Name"
genoutput = genoutput & randomlastname() & vbTab
Case "Decimal"
genoutput = genoutput & gendecimal(CDbl(decimal1.text,decimal2.text)) & vbtab )
Case "Integer"
genoutput = (genoutput & geninteger(CInt(integer1.text,integer2.text)) & vbtab)
Case "Birthday"
genoutput = (genoutput & birthday(CInt(year1.text,year2.text)) & vbtab &)
End Select
I am trying to get a string that looks like this and runs
outfile.Write(randomfirstname() & vbTab & randomlastname() & vbTab & gendecimal(CDbl(decimal1.text,decimal2.text)) & vbTab & (CInt(integer1.text,integer2.text)) & vbTab & birthday(CInt(year1.text,year2.text)) & vbCrLf)
This will work if you remove the quotes from hello() & vbtab & goodbye(), but as JohnFx said, it seems like an unusual and unnecessary way to do it.
I think you might be looking for something more like:
1) ListBox1.Items.Add("Hello"), .Add("Goodbye"), ...
2) If ListBox1.ListIndex = 0 then call hello, else if ...
Related
Good Day! I'm clueless on visual studio. Please Help me.
I have a datagridview that has database access file.
its bound to textboxes
now i have a search button that has a textbox too.
it runs fine but it needs to input the complete name.
I want it to be when you just input a letter it shows all the names that has/have that letter.
for example if i type "A" all names in the the database that has letter "A" on it will show.
but in this case
if i type "AGING" it will say cant find. It must be "AGING OVEN" for it to show the result.
here is my code.
please help thanks
Private Sub SearchBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchBtn.Click
On Error GoTo SearchErr
If SearchTxtbox.Text = "" Then
Exit Sub
Else
Dim cantFind As String = SearchTxtbox.Text
TOOLSANDEQUIPMENTBindingSource.Filter = "(CONVERT(ID, 'System.String') like '" & SearchTxtbox.Text & "')" & _
"OR ([TOOL and EQUIPMENT] like '" & SearchTxtbox.Text & "') OR ([QUANTITY] like '" & SearchTxtbox.Text & "')" & _
"OR ([ITEM NO] like '" & SearchTxtbox.Text & "')" & _
"OR ([PART NO] like '" & SearchTxtbox.Text & "')" & _
"OR ([DATE MODIFIED] like '" & SearchTxtbox.Text & "')"
If TOOLSANDEQUIPMENTBindingSource.Count <> 0 Then
With TEDataGridView
.DataSource = TOOLSANDEQUIPMENTBindingSource
End With
Else
MsgBox("--> " & cantFind & vbNewLine & _
"The search item was not found.", _
MsgBoxStyle.Information, "Hey Boss!")
TOOLSANDEQUIPMENTBindingSource.Filter = Nothing
With TEDataGridView
.ClearSelection()
.ReadOnly = True
.MultiSelect = False
.DataSource = TOOLSANDEQUIPMENTBindingSource
End With
End If
End If
ErrEx:
Exit Sub
SearchErr:
MsgBox("Error Number " & Err.Number & vbNewLine & _
"Error Description " & Err.Description, MsgBoxStyle.Critical, _
"Reser Error!")
Resume ErrEx
End Sub
A form's button click opens an access report that comes up with data. The parameters are used with a pass-through query to an SQL stored procedure which returns records. The report does not come up Modal and I would like it to remain that way. However, if the user does not close the report before going back to the form and tries to set new parameters, the report remains open in the background and upon the button click the report is brought to the fore with old parameters and data and not refreshed with new parameters/data.
One option is to go Modal with the report but that makes for rough transitions with the user having to actively close the report. The other option is to close the report during retries which is what I have been trying. I have tried:
If CurrentProject.AllReports(rpt_ptq_uspWorkCentreReport).IsLoaded Then
DoCmd.Close acReport, rpt_ptq_uspWorkCentreReport, acSaveNo
in several different locations: _MousedDown, as the first If in the _Click, and _BeforeInsert. Each time CurrentProject.AllReports(rpt_ptq_uspWorkCentreReport).IsLoaded comes up false during the second pass when the report is sitting in the background and the form is being reworked with the next tries new parameters. Also during the second attempt the .OpenReport line fails with an SQL error because strSQLP1 is incomplete. Here's the _Click event:
Private Sub btnPreviewP1_Click()
If (Me.txtToDateP1 < Me.txtFromDateP1) Then
MsgBox ("The From Date must occurr before the To Date!")
End If
Dim strFromDateHMS As String
Dim strToDateHMS As String
Dim strSQLP1 As String
Dim strOpenArgs As String
strFromDateHMS = Format(Me.txtFromDateP1, "yyyy-mm-dd") & " " & Me.cboFromHourP1 & ":" & Me.cboFromMinuteP1 & ":" & Me.cboFromSecondP1
strToDateHMS = Format(Me.txtToDateP1, "yyyy-mm-dd") & " " & Me.cboToHourP1 & ":" & Me.cboToMinuteP1 & ":" & Me.cboToSecondP1
strSQLP1 = "exec dbo.uspWorkCentreReport '" & strFromDateHMS & "','" & strToDateHMS & "','" & strWCP1 & "'," & strShiftP1
strOpenArgs = Me.RecordSource & "|" & strFromDateHMS & "|" & strToDateHMS & "|" & strWCP1 & "|" & strShiftP1
' This line is all that's needed to modify the PT query
CurrentDb.QueryDefs("ptq_uspWorkCentreReport").SQL = strSQLP1
DoCmd.OpenReport "rpt_ptq_uspWorkCentreReport", acViewReport, , , , strOpenArgs
End Sub
And the _MouseDown where the .AllReports is currently:
Private Sub btnPreviewP1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If CurrentProject.AllReports(rpt_ptq_uspWorkCentreReport).IsLoaded Then
DoCmd.Close acReport, rpt_ptq_uspWorkCentreReport, acSaveNo
End If
End Sub
This is the Report_Open:
Private Sub Report_Open(Cancel As Integer)
Dim SplitOpenArgs() As String
SplitOpenArgs = Split(Me.OpenArgs, "|")
Me.lblFromDate.Caption = SplitOpenArgs(1)
Me.lblToDate.Caption = SplitOpenArgs(2)
Me.lblWC.Caption = SplitOpenArgs(3)
Me.lblShift.Caption = SplitOpenArgs(4)
End Sub
Why not just close report before OpenReport? I modified your code:
Private Sub btnPreviewP1_Click()
If (Me.txtToDateP1 < Me.txtFromDateP1) Then
MsgBox ("The From Date must occurr before the To Date!")
End If
Dim strFromDateHMS As String
Dim strToDateHMS As String
Dim strSQLP1 As String
Dim strOpenArgs As String
Dim R
strFromDateHMS = Format(Me.txtFromDateP1, "yyyy-mm-dd") & " " & Me.cboFromHourP1 & ":" & Me.cboFromMinuteP1 & ":" & Me.cboFromSecondP1
strToDateHMS = Format(Me.txtToDateP1, "yyyy-mm-dd") & " " & Me.cboToHourP1 & ":" & Me.cboToMinuteP1 & ":" & Me.cboToSecondP1
strSQLP1 = "exec dbo.uspWorkCentreReport '" & strFromDateHMS & "','" & strToDateHMS & "','" & strWCP1 & "'," & strShiftP1
strOpenArgs = Me.RecordSource & "|" & strFromDateHMS & "|" & strToDateHMS & "|" & strWCP1 & "|" & strShiftP1
' This line is all that's needed to modify the PT query
CurrentDb.QueryDefs("ptq_uspWorkCentreReport").SQL = strSQLP1
' Check if report is open and close it without saving:
For Each R In Reports
If R.Name = "rpt_ptq_uspWorkCentreReport" Then
DoCmd.Close acReport, "rpt_ptq_uspWorkCentreReport", acSaveNo
Exit For
End If
Next R
DoCmd.OpenReport "rpt_ptq_uspWorkCentreReport", acViewReport, , , , strOpenArgs
End Sub
I am having an application that uses Microsoft Word 2016 / the Interop interface to call the replace function. This way the application replaces some texts like 'Customername' to the actual name of the customer. Surely this is not the best way to do so, but thats how the application was build back in the days. Now I have to do some adjustments to the formatting facing a problem with the named function.
One of the Texts getting replaced is "[TELNR]" , beeing replaced with all known numbers of the customer, one number per line. Inserting New Lines as vbCr works great on a blank page as you can see top of the screenshot. The same called function will not put a new lines into a table (second page on the left) and won't even touch a textbox (second page on the right).
I have tried passing Line breaks as ^p, \n\r, \n, vbClRf / vbNewLine, vbCr. None of these will work.
I haven't found anything usefull on google or SO. Do you have ideas or a reason what might cause or even solve the problem?
#Region "Sample Strings"
Dim sample1 As String = "t:022220000000" & vbNewLine & "h:022221111111" & vbNewLine & ":0222222222222" & vbNewLine & "f:022223333333"
Dim sample2 As String = "t:022220000000" & vbCr & "h:022221111111" & vbCr & ":0222222222222" & vbCr & "f:022223333333"
Dim sample3 As String = "t:022220000000" & "^p" & "h:022221111111" & "^p" & ":0222222222222" & "^p" & "f:022223333333"
Dim sample4 As String = "t:022220000000" & "\n" & "h:022221111111" & "\n" & ":0222222222222" & "\n" & "f:022223333333"
Dim sample5 As String = "t:022220000000" & "\n\r" & "h:022221111111" & "\n\r" & ":0222222222222" & "\n\r" & "f:022223333333"
Dim sample6 As String = "t:022220000000" & vbCrLf & "h:022221111111" & vbCrLf & ":0222222222222" & vbCrLf & "f:022223333333"
#End Region
Private Sub replaceText(file As Microsoft.Office.Interop.Word.Document, find As String, replaceWith As String)
// First line was commented out for the ^p try
If replaceWith.Contains("^") Then replaceWith = replaceWith.Replace("^", "")
file.Content.Find.Execute(FindText:=find, ReplaceWith:=replaceWith, Replace:=Word.WdReplace.wdReplaceAll)
End Sub
The following was function was used to insert the textbox.
I am trying to write an xml file ussing a little less conventional method, Just for those wondering there's a long story too why I am doing this. The real point is though that I cant seem to get the Tag named to write its value to the resulting XML file and I cant fuigureout why... could somebody help me with this...
The code as follows...
Private Sub SaveToolStripMenuItem2_Click(sender As Object, e As EventArgs) Handles SaveToolStripMenuItem2.Click
'define a save dialog
Dim save_file As New SaveFileDialog
'give its extension...
save_file.RestoreDirectory = True
save_file.InitialDirectory = My.Application.Info.DirectoryPath & " \ LIBRARY"
save_file.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"
save_file.FilterIndex = 1
''create a datatable
'Dim my_datatable As New DataTable
'if ok click
If save_file.ShowDialog() = DialogResult.OK Then
Using writer As New IO.StreamWriter(save_file.FileName)
writer.WriteLine("<COMPELATION>")
For Each row As DataGridViewRow In Me.DataGridView1.Rows
If Not row.IsNewRow Then
writer.WriteLine(String.Format(vbCrLf & vbTab & "<Data>" & vbCrLf & vbTab & vbTab & "<DEF>{0}</DEF>" & vbCrLf & vbTab & vbTab & "<HGT>{1}</HGT>" & vbCrLf & vbTab & vbTab & "<LEN>{2}</LEN>" & vbCrLf & vbTab & vbTab & "<WDT>{3}</WDT>" & vbCrLf & vbTab & vbTab & "<THK>{4}</THK>" & vbCrLf & vbTab & vbTab & "<AN1>{5}</AN1>" & vbCrLf & vbTab & vbTab & "<AN2>{6}</AN2>" & vbCrLf & vbTab & vbTab & "<MAT>{7}</MAT>" & vbCrLf & vbTab & "</Data>",
row.Cells(0).Value,
row.Cells(1).Value,
row.Cells(2).Value,
row.Cells(3).Value,
row.Cells(4).Value,
row.Cells(5).Value,
row.Cells(6).Value,
row.Cells(7).Value))
End If
Next
writer.WriteLine("</COMPELATION>")
writer.Close()
End Using
Dim result1 As DialogResult = MessageBox.Show("Would you like to use this file as the default library?", "Information", MessageBoxButtons.YesNo)
If result1 = DialogResult.Yes Then
'Set the new file as the default XML...
My.Settings.DEFAULTXML = save_file.FileName
'Reload and bind the data source...
Me.Refresh()
Else
End If
End If
End Sub
I have data in dataset which I am loopping to build up data for the email the data is as follows but I am using the following to produce the email using tabs but it doesnt see very iffiencet i can only use plain text is their a better way to get it to format nicer like using the datatable sizes or something
Dim dataForEmail As String = ""
Dim msg As String = ""
msg = "The Following Deliverys where processed for the Following Ordernumbers at " & DateTime.Now.ToString() & Chr(13)
dataForEmail = "Order Number" & vbTab & "BarCode" & vbTab & vbTab & vbTab & "Description" & vbTab & vbTab & vbTab & vbTab & vbTab & "Brand" & vbTab & vbTab & vbTab & "Size" & vbTab & "Colour" & vbTab & "Price" & vbTab & "RRP" & vbTab & vbTab & vbTab & "Qty" & Chr(13)
Dim totalcost As Decimal
If Not IsNothing(results) AndAlso Not IsNothing(results.Rows) _
AndAlso results.Rows.Count > 0 Then
For Each thisRow As DataRow In results.Rows
CreateDeliveryIncFileForGemini(thisRow)
totalcost = totalcost + thisRow.Item("RRPPrice")
dataForEmail = dataForEmail & BuildReportFoEmail(thisRow)
connection.ExecuteNonQuerySql(scriptBuilder.SetDeliveryStatus(2, 1, thisRow.Item("r3DeliveryId")))
Next
connection.ExecuteNonQuerySql(scriptBuilder.SetDeliveryStatus(1, 0))
dataForEmail = dataForEmail & vbCrLf & "Total Price " & totalcost.ToString()
SendEmailViaWebService(dataForEmail, cfb.EmailForDeliverys, cfb.FullNameForEmailSubject, msg)
End If
CloseConnection()