I have some computers with modems and others without using the same database. They db needs to determine if there is a modem installed. I found code created by KHaled El-Menshawy on the Internet which has the potential to do exactly what I want it to do but I get an "Object required" error. I think this is a simple fix, but I don't know how this object should be declared. Can anyone figure out the missing code? Here is his code:
Public Function CheckModem()
On Error GoTo Errr
If ProgBar.Value = 100 Then
ProgBar.Value = 0
End If
Port = 1
PortinG:
MSComm1.CommPort = Port
MSComm1.PortOpen = True
ProgBar.Value = ProgBar.Value + 20
Label1.Caption = ProgBar.Value & "%"
Form1.MSComm1.Settings = "9600,N,8,1"
MSComm1.Output = "AT" + Chr$(13)
X = 1
Do: DoEvents
X = X + 1
If X = 1000 Then MSComm1.Output = "AT" + Chr$(13)
If X = 2000 Then MSComm1.Output = "AT" + Chr$(13)
If X = 3000 Then MSComm1.Output = "AT" + Chr$(13)
If X = 4000 Then MSComm1.Output = "AT" + Chr$(13)
If X = 5000 Then MSComm1.Output = "AT" + Chr$(13)
If X = 6000 Then MSComm1.Output = "AT" + Chr$(13)
If X = 7000 Then
MSComm1.PortOpen = False
Port = Port + 1
GoTo PortinG:
If MSComm1.CommPort >= 6 Then
Errr:
MsgBox "Can't Find Modem"
GoTo done
End If
End If
Loop Until MSComm1.InBufferCount >= 2
instring = MSComm1.Input
MSComm1.PortOpen = False
ProgBar.Value = 100
Label1.Caption = ProgBar.Value & "%"
Text1.Text = "com" & Port 'MSComm1.CommPort & instring
MsgBox "Modem found On Com" & Port
done:
End Function
MsComm1, if you are just copy and pasting from the code looks like it is a MsComm control object. You will have to add it as an additional control to the form, and then you can access its properties.
I suggest avoiding copy and pasting code that you don't understand, try to understand what it is doing and why. Alternatively, this link (from this question) gives a completely different way to do it, avoiding the need to add the control to the form.
Related
This SELECT CASE scenario is working for me but I think the code can be more friendly ... any advice would be very helpful.
Select Case True 'select case where worker name and action is true then in each case RSworkhours.addnew
Case Me.Worker1.Value <> "" And Me.fw1a1 = 1
With RsWorkHours
.AddNew
!WorkerID = Me.Worker1
!Date = Me.TxtDate
!StandardTime = Me.w1a1s
!Overtime = Me.w1a1o
!Doubletime = Me.w1a1d
!ScaffoldID = Me.cboScaffnum
.Update
End With
Me.fw1a1 = 0
GoTo WorkerHours
Case Me.Worker1.Value <> "" And Me.fw1a2 = 1
With RsWorkHours
.AddNew
!WorkerID = Me.Worker1
!Date = Me.TxtDate
!StandardTime = Me.w1a2s
!Overtime = Me.w1a2o
!Doubletime = Me.w1a2d
!ScaffoldID = Me.cboScaffnum
.Update
End With
Me.fw1a2 = 0
GoTo WorkerHours
The Code iterates through this Select Case 80 times, if there are 16 workers and each have 5 actions.
I was thinking maybe having a loop that modifies the number within the arguments like:
for each x to 16
for each y to 5
If Me.worker & x & .Value <> "" And Me.fw & x & a & y Then
With Recordset
.AddNew
'insert stuff
.Update
End With
End If
Next y
Next x
Does anyone have any insight?
Thank you in advance.
-Matt
You can access all controls by their name from the Controls collection.
Just pass the name of a control and you will get to that control - the name is a string and can of course be dynamic.
Dim x As Long, y As Long
Dim WorkerX As Control, wXaYs As Control, wXaYo As Control, wXaYd As Control
For x = 1 To 16
For y = 1 To 5
Set WorkerX = Me.Controls("Worker" & x)
Set wXaYs = Me.Controls("w" & x & "a" & y & "s")
Set wXaYo = Me.Controls("w" & x & "a" & y & "o")
Set wXaYd = Me.Controls("w" & x & "a" & y & "d")
If WorkerX.Value > "" And wXaYs.Value > "" Then
With Recordset
.AddNew
!WorkerID = WorkerX.Value
!Date = Me.TxtDate
!StandardTime = wXaYs.Value
!Overtime = wXaYo.Value
!Doubletime = wXaYd.Value
!ScaffoldID = Me.cboScaffnum
.Update
End With
End If
Next y
Next x
I am using the the program FrontlineSMS and some code written in VBScript to take incoming SMS messages and log them to a CSV file. However, random characters such as percents and numbers are ending up in the CSV file even though they are not in the SMS. Below is an example of what I mean:
I send an SMS with my phone to the modem connected to the computer reading
"07/12/2013 11:29:56 25 Happy Holidays"
The modem then receives the message and passes it on the script, which outputs it to a .CSV file. However when I open the file it reads:
"07%2F12%2F2013 | 11%3A29%3A56 | 25 | Happy | Holidays |
Where each word is in its own cell. I need help in figuring out how to get rid of the extra characters that show up (like "%2F"), my guess is that it has to do with the encryption/decryption of the characters when converting to .CSV but I don't know where to start looking to solve this.
Edit: I found out that it has to do with the ASCII coding. "%2F" is Hex for a slash "/", but I still don't know how to prevent this from happening.
Thanks!
Here is the entire script:
Option Explicit
Dim first, secnd
Dim fso, outFile
Dim strFile, strValues, strLine, strInfo
Dim stamp, num, i, identify
Const ForAppending = 8
'error handling/format
'Settings
identify = WScript.Arguments(1)
CStr(identify)
stamp = MyDate()
CStr(stamp)
strFile = "C:\SMScomm\Log\" &identify &" " &stamp & " log.csv"
'Create the file system object
Set fso = CreateObject("Scripting.FileSystemObject")
'Check whether argument were passed
If WScript.Arguments.Count <> 1 Then
WScript.Echo "No arguments were passed"
End If
strInfo = WScript.Arguments(0)
'Replace(strInfo, "%2C", ",")
'Split the argument from FSMS so it reads normally
strValues = Split(strInfo, "+")
'Open to append
Set outFile = fso.OpenTextFile(strFile, ForAppending, True)
num = UBound(strValues)
If num = 0 then
WScript.Echo "Formatting error"
End If
Do while i < num + 1
strValues(i) = strValues(i) & ","
i = i + 1
Loop
'Write to the .csv
i = 0
Do while i < num + 1
outFile.Write(strValues(i) + " ")
i = i + 1
Loop
outFile.WriteBlankLines(1)
'Close the file
outFile.Close
'Clean up
Set outFile = Nothing
Set fso = Nothing
Function MyDate()
Dim dteCurrent, dteDay, dteMonth, dteYear
dteCurrent = Date()
dteDay = Day(dteCurrent)
dteMonth = Month(dteCurrent)
dteYear = Year(dteCurrent)
MyDate = dteMonth & "-" & dteDay & "-" & dteYear
End Function
It looks like either your script or the modem is converting special characters such as "/" into their Hex format.
Can you post the script that dumps this information into CSV format?
Option Explicit
Dim first, secnd
Dim fso, outFile
Dim strFile, strValues, strLine, strInfo
Dim stamp, num, i, identify
Const ForAppending = 8
'error handling/format
'Settings
identify = WScript.Arguments(1)
CStr(identify)
stamp = MyDate()
CStr(stamp)
strFile = "C:\SMScomm\Log\" &identify &" " &stamp & " log.csv"
'Create the file system object
Set fso = CreateObject("Scripting.FileSystemObject")
'Check whether argument were passed
If WScript.Arguments.Count <> 1 Then
WScript.Echo "No arguments were passed"
End If
strInfo = WScript.Arguments(0)
'Replace(strInfo, "%2C", ",")
'Split the argument from FSMS so it reads normally
strValues = Split(strInfo, "+")
'Open to append
Set outFile = fso.OpenTextFile(strFile, ForAppending, True)
num = UBound(strValues)
If num = 0 then
WScript.Echo "Formatting error"
End If
Do while i < num + 1
strValues(i) = strValues(i) & ","
i = i + 1
Loop
'Write to the .csv
i = 0
Do while i < num + 1
Replace(strValues(i), '%2F', '/')
Replace(strValues(i), '%3A', ':')
outFile.Write(strValues(i) + " ")
i = i + 1
Loop
outFile.WriteBlankLines(1)
'Close the file
outFile.Close
'Clean up
Set outFile = Nothing
Set fso = Nothing
Function MyDate()
Dim dteCurrent, dteDay, dteMonth, dteYear
dteCurrent = Date()
dteDay = Day(dteCurrent)
dteMonth = Month(dteCurrent)
dteYear = Year(dteCurrent)
MyDate = dteMonth & "-" & dteDay & "-" & dteYear
End Function
I am sure there is a more elegant way of doing this but it should solve your problem.
I have developed a winform which requires constant contact with a mysql database to make sure all "calls" are fetched and up to date - the problem I have run into is that my listview is only being populated with 1 line per timer click. this timer should activate a while statement that should process all data and in fact should also be clearing the listview to receive updated data. why is my listview only populating 1 item per tick?
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
ListView2.Items.Clear()
con.ConnectionString = "server=localhost;" _
& "user id=username;" _
& "password=password;" _
& "database=DMT"
adptr = New MySqlDataAdapter("SELECT * , s.fid AS sfid, s.name AS sname, s.faddress AS sfaddress, s.fcity AS sfcity, s.fstate AS sfstate, s.fcontnumb AS sfcontnumb, s.fcontname AS sfcontname, s.fcontract AS sfcontract, d.fid AS dfid, d.name AS dname, d.faddress AS dfaddress, d.fcity AS dfcity, d.fstate AS dfstate, d.fcontnumb AS dfcontnumb, d.fcontname AS dfcontname, d.fcontract AS dfcontract FROM calls c LEFT JOIN facilities s ON c.Scene = s.fid LEFT JOIN facilities d ON c.Dest = d.fid WHERE putime < now( ) + INTERVAL 12 HOUR && Rdisp IS NULL ORDER BY putime desc", con)
Try
adptr.Fill(pendrun)
Catch err As Exception
Dim strError As String = "Exception: & err.ToString()"
End Try
If pendrun.Rows.Count > 0 Then
While pop < pendrun.Rows.Count - 1
TempStr(0) = pendrun.Rows(pop)("RID")
Select Case pendrun.Rows(pop)("Utype")
Case 1
TempStr(1) = "BLS Ambulance"
Case 2
TempStr(1) = "ALS Ambulance"
Case 3
TempStr(1) = "SCT Ambulance"
Case 4
TempStr(1) = "Wheelchair Van"
Case 5
TempStr(1) = "Taxi"
End Select
Select Case pendrun.Rows(pop)("Curgency")
Case 1
TempStr(2) = "Scheduled"
Case 2
TempStr(2) = "Non-Scheduled"
Case 3
TempStr(2) = "ASAP"
Case 4
TempStr(2) = "STAT"
End Select
TempStr(3) = pendrun.Rows(pop)("Pname")
TempStr(4) = pendrun.Rows(pop)("Texttime")
TempStr(5) = pendrun.Rows(pop)("sname") & " - " & pendrun.Rows(pop)("sfaddress") & ", " & pendrun.Rows(pop)("sfcity") & ", " & pendrun.Rows(pop)("sfstate")
TempStr(6) = pendrun.Rows(pop)("dname") & " - " & pendrun.Rows(pop)("dfaddress") & ", " & pendrun.Rows(pop)("dfcity") & ", " & pendrun.Rows(pop)("dfstate")
TempNode = New ListViewItem(TempStr)
ListView2.Items.Add(TempNode)
pop += 1
End While
End If
End Sub
I have verified it is in fact linked to the timer directly (1 item per tick) by varying the timer from 1 second to 30 seconds and it does directly change this.
Your code never resets "pop"'s value. That's what's causing trouble, I'm pretty sure. It keeps incrementing 1 value every tick, never able to do all of them because pop is set to one less than the while's max.
Sorry for the messy outlook. This is basically a .inc file for a asp website. Currently, we have migrated from our current MySQL to MSSQL 2008. In MySQL, im able to connect to the database. But im unable to connect it under MSSQL 2008. The script works fine in MySQL. Pls help.
Information 1 : I'm using Dreamweaver.
Information 2 : I have tried strConnect = "Provider=sqloledb;Library=DBMSSOCN;Data Source=xx.xx.xx.xx;1433; Initial Catalog=mydatabasename;User Id=userID;Password=password;"
Information 3 : I can't access to the database thru the website, this is the error msg i get 500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
Information 4 :i'm lost for ideas. I searched everywhere in http://www.connectionstrings.com/sql-server-2008, http://support.microsoft.com/kb/238949, still no luck.
Information 5 : I have tried using .udl file to get the connection string. Whenever i test connection, it works perfectly shows connection passed
`<% On Error Resume Next
Set objConn = Nothing
strConnect = "Provider=sqloledb;Network Library=DBMSSOCN;Data Source=ABC-EF-SQLS01"
"Initial Catalog=mydatabasename;"
"User Id=userID;Password=password;"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strConnect
Function UserIP()
UserIP = Request.ServerVariables ( "HTTP_X_FORWARD_FOR" )
If UserIP = "" Then
UserIP = Request.ServerVariables ( "REMOTE_ADDR" )
End If
End Function
Function BinaryToString(Binary)
Dim cl1, cl2, cl3, pl1, pl2, pl3
Dim L
cl1 = 1
cl2 = 1
cl3 = 1
L = LenB(Binary)
Do While cl1<=L
pl3 = pl3 & Chr(AscB(MidB(Binary,cl1,1)))
cl1 = cl1 + 1
cl3 = cl3 + 1
If cl3>300 Then
pl2 = pl2 & pl3
pl3 = ""
cl3 = 1
cl2 = cl2 + 1
If cl2>200 Then
pl1 = pl1 & pl2
pl2 = ""
cl2 = 1
End If
End If
Loop
BinaryToString = nl2br(pl1 & pl2 & pl3)
End Function
Function nl2br(str)
If Not isNull(str) Then
nl2br=replace(str,VbCrLf, "<br > ")
End If
End function
Function AddZeros(str)
iLength = len(str)
iZeros = 9 - iLength
For i=1 to iZeros
str = "0" & str
Next
AddZeros = "<font color=green><b>AKC-"&str&"</b></font>"
End Function
Function DisplayDateFormat(str)
arrDate = Split(CStr(str),"/")
DisplayDateFormat = arrDate(1)&"-"&arrDate(0)&"-"&arrDate(2)
End Function
Function DBDateFormat(str)
End Function
Function doubleQuote(ByVal fixText)
doubleQuote = Replace(fixText, "'", "''")
End Function
%>
should be
Provider=sqloledb;Network Library=DBMSSOCN;Data Source=xx.xx.xx.xx,1433
note the comma for the explicit port and the Network word.
Though it may be best to just use Data Source=xxxx;
and set up network library specifics via the xxxx alias in cliconfg
So I have some VBA for taking charts built with the Form's Chart Wizard, and automatically inserting it into PowerPoint Presentation slides. I use those chart-forms as sub forms within a larger forms that has parameters the user can select to determine what is on the chart. The idea is that the user can determine the parameter, build the chart to his/her liking, and click a button and have it in a ppt slide with the company's background template, blah blah blah.....
So it works, though it is very bulky in terms of the amount of objects I have to use to accomplish this.
I use expressions such as the following:
like forms!frmMain.Month&*
to get the input values into the saved queries, which was fine when i first started, but it went over so well and they want so many options, that it is driving the number of saved queries/objects up. I need several saved forms with charts because of the number of different types of charts I need to have this be able to handle.
SO FINALLY TO MY QUESTION:
I would much rather do all this on the fly with some VBA. I know how to insert list boxes, and text boxes on a form, and I know how to use SQL in VBA to get the values I want from tables/queries using VBA, I just don't know if there is some vba I can use to set the data values of the charts from a resulting recordset:
DIM rs AS DAO.Rescordset
DIM db AS DAO.Database
DIM sql AS String
sql = "SELECT TOP 5 Count(tblMain.TransactionID) AS Total, tblMain.Location FROM
tblMain WHERE (((tblMain.Month) = """ & me.txtMonth & """ )) ORDER BY Count
(tblMain.TransactionID) DESC;"
set db = currentDB
set rs = db.OpenRecordSet(sql)
rs.movefirst
some kind of cool code in here to make this recordset
the data of chart in frmChart ("Chart01")
thanks for your help. apologies for the length of the explanation.
It is possible to change the dataset directly in vba as I have managed to do it. However the performance is not so good so I went back to filling the results to a temp table and basing the graph on that ( see my only asked stackoverflow question) however if the dataset is quite small then you can certainly make it work. I'm not in the office but if you want code I can post on Monday
EDIT: here is the old code module I used. This is the full thing but the key part you are going to be looking at is the part about opening the datasheet of the graph and then changing the value of it like this .cells(1,0)="badger".
I enevtly dumped this method and went with a temp table as in my app the graph is redraw quite a lot and I needed to go for the fastest possible method to give a "real time" feel to it but it might be just fine for your needs
Public Sub Draw_graph(strGraph_type As String)
Dim objGraph As Object
Dim objDS As Object
Dim i As Byte
On Error GoTo Error_trap
Dim lRT_actual As Long
Dim lRT_forecast As Long
Dim Start_time As Long
Dim aCell_buffer(49, 4) As Variant
Me.acxProgress_bar.Visible = True
Me.acxProgress_bar.Value = 0
Set objGraph = Me.oleCall_graph.Object
Set objDS = objGraph.Application.datasheet
Start_time = GetTime()
With objDS
.cells.Clear
Select Case strGraph_type
Case Is = "Agents"
'**************************
'** Draw the agent graph **
'**************************
.cells(1, 1) = "Start Time"
.cells(1, 2) = "Provided"
.cells(1, 3) = "Required"
.cells(1, 4) = "Actual Required"
For i = 1 To 48
.cells(i + 1, 1) = Format(DateAdd("n", (i - 1) * 15, "08:00:00"), "HHMM")
If Me.Controls("txtAgents_pro_" & i) > 0 Then
.cells(i + 1, 2) = Me.Controls("txtAgents_pro_" & i) + Me.Controls("txtAgents_add_" & i)
Else
.cells(i + 1, 2) = 0
End If
If Me.Controls("txtAgents_req_" & i) > 0 Then
.cells(i + 1, 3) = Me.Controls("txtAgents_req_" & i)
End If
If Me.Controls("txtActual_" & i) > 0 Then
.cells(i + 1, 4) = Erlang_Agents(Me.txtServiceLevel, Me.txtServiceTime, Me.Controls("txtActual_" & i) * 4, Me.txtAVHT + CLng(Nz(Me.txtDaily_AVHT_DV, 0)))
End If
'update the progress bar
If Me.acxProgress_bar.Value + 2 < 100 Then
Me.acxProgress_bar.Value = Me.acxProgress_bar.Value + 2
Else
Me.acxProgress_bar.Value = 90
End If
Next i
Case Is = "Calls"
'**************************
'** Draw the Calls graph **
'**************************
.cells(1, 1) = "Start Time"
.cells(1, 2) = "Forecast"
.cells(1, 3) = "Actual"
For i = 1 To 48
.cells(i + 1, 1) = Format(DateAdd("n", (i - 1) * 15, "08:00:00"), "HHMM")
If Me.Controls("txtForecast_" & i) > 0 Then
.cells(i + 1, 2) = Me.Controls("txtForecast_" & i)
Else
.cells(i + 1, 2) = 0
End If
If Me.Controls("txtActual_" & i) > 0 Then
.cells(i + 1, 3) = Me.Controls("txtActual_" & i)
End If
If Me.acxProgress_bar.Value + 2 < 100 Then
Me.acxProgress_bar.Value = Me.acxProgress_bar.Value + 2
Else
Me.acxProgress_bar.Value = 90
End If
Next i
Case Is = "Call Deviation"
'**************************
'** Draw the Call Deviation graph **
'**************************
.cells(1, 1) = "Start Time"
.cells(1, 2) = "Deviation"
lRT_actual = 0
lRT_forecast = 0
For i = 1 To 48
lRT_actual = lRT_actual + Me.Controls("txtActual_" & i)
lRT_forecast = lRT_forecast + Me.Controls("txtForecast_" & i)
.cells(i + 1, 1) = Format(DateAdd("n", (i - 1) * 15, "08:00:00"), "HHMM")
.cells(i + 1, 2) = lRT_actual - lRT_forecast
If Me.acxProgress_bar.Value + 2 < 100 Then
Me.acxProgress_bar.Value = Me.acxProgress_bar.Value + 2
Else
Me.acxProgress_bar.Value = 90
End If
Next i
Case Is = "Call Deviation %"
'**************************
'** Draw the Call Deviation % graph **
'**************************
.cells(1, 1) = "Start Time"
.cells(1, 2) = "Deviation"
lRT_actual = 0
lRT_forecast = 0
For i = 1 To 48
lRT_actual = lRT_actual + Me.Controls("txtActual_" & i)
lRT_forecast = lRT_forecast + Me.Controls("txtForecast_" & i)
.cells(i + 1, 1) = Format(DateAdd("n", (i - 1) * 15, "08:00:00"), "HHMM")
If lRT_forecast > 0 Then
.cells(i + 1, 2) = (lRT_actual - lRT_forecast) / lRT_forecast
End If
If Me.acxProgress_bar.Value + 2 < 100 Then
Me.acxProgress_bar.Value = Me.acxProgress_bar.Value + 2
Else
Me.acxProgress_bar.Value = 90
End If
Next i
Case Is = "SLA"
'**************************
'*** Draw the SLA graph ***
'**************************
.cells(1, 1) = "Start Time"
.cells(1, 2) = "SLA"
.cells(1, 3) = "Actual SLA"
For i = 1 To 48
.cells(i + 1, 1) = Format(DateAdd("n", (i - 1) * 15, "08:00:00"), "HHMM")
If Me.Controls("txtSLA_" & i) > 0 Then
.cells(i + 1, 2) = Me.Controls("txtSLA_" & i) / 100
Else
.cells(i + 1, 2) = 0
End If
If Me.Controls("txtActual_SLA_" & i) > 0 Then
.cells(i + 1, 3) = Me.Controls("txtActual_SLA_" & i)
End If
If Me.acxProgress_bar.Value + 2 < 100 Then
Me.acxProgress_bar.Value = Me.acxProgress_bar.Value + 2
Else
Me.acxProgress_bar.Value = 90
End If
Next i
End Select
End With
Set objDS = Nothing
Set objGraph = Nothing
Me.acxProgress_bar.Visible = False
Exit Sub
Error_trap:
DoCmd.Hourglass False
MsgBox "An error happened in sub Draw_graph, error description, " & Err.Description, vbCritical, "Tracker 3"
End Sub
One very easy way of doing this is to base the chart on a query and update the query, for example:
strSQL = "SELECT ..."
QueryName = "qryByHospital"
If IsNull(DLookup("Name", "MsysObjects", "Name='" & QueryName & "'")) Then
CurrentDb.CreateQueryDef QueryName, strSQL
Else
CurrentDb.QueryDefs(QueryName).SQL = strSQL
End If
DoCmd.OpenReport "rptChartByHospital", acViewPreview