Click here to Skip to main content
15,887,596 members
Home / Discussions / Visual Basic
   

Visual Basic

 
SuggestionRe: Sending email through VB6 Pin
Richard MacCutchan8-Nov-14 2:46
mveRichard MacCutchan8-Nov-14 2:46 
AnswerRe: Sending email through VB6 Pin
Mycroft Holmes8-Nov-14 12:28
professionalMycroft Holmes8-Nov-14 12:28 
GeneralRe: Sending email through VB6 Pin
ACIVE11-Nov-14 13:24
ACIVE11-Nov-14 13:24 
GeneralRe: Sending email through VB6 Pin
Mycroft Holmes11-Nov-14 13:42
professionalMycroft Holmes11-Nov-14 13:42 
GeneralRe: Sending email through VB6 Pin
ACIVE12-Nov-14 0:39
ACIVE12-Nov-14 0:39 
Question1073479673(c0040007) Pin
Krishna Kamal7-Nov-14 18:44
professionalKrishna Kamal7-Nov-14 18:44 
AnswerRe: 1073479673(c0040007) Pin
Richard MacCutchan7-Nov-14 22:05
mveRichard MacCutchan7-Nov-14 22:05 
GeneralRe: 1073479673(c0040007) Pin
Krishna Kamal10-Nov-14 22:17
professionalKrishna Kamal10-Nov-14 22:17 
Option Explicit
Dim srv As New OPCServer \\the error code is showing on this area{The MSDN collection does not

exist;Please reinstall MSDN}\\
Dim StrName As String
Dim WithEvents grp As OPCGroup
Dim itm As OPCItem
Dim StrQuery As String
Dim StrQuery1 As String
Dim StrRepQuery As String
Dim strFromDate As String
Dim strToDate As String
Dim Cn As ADODB.Connection
Dim Rst As ADODB.Recordset
Dim RepRst As ADODB.Recordset
Dim TempRst As ADODB.Recordset

Private Function Validate()
If IsNull(DTPFromDate.Value) Or IsNull(DTPToDate.Value) Then
MsgBox "Please Select From & To Date.", vbInformation, "Date Massage."
Validate = True
Else
Validate = False
End If
End Function

Private Sub RepQuary()
On Error GoTo ErrorHandler
StrRepQuery = ""
StrRepQuery = "SELECT UNIQUEID AS UID FROM TAGDETAIL WHERE UCASE(TAGNAME) LIKE '%" & UCase(StrName) & "%'"
Set RepRst = Cn.Execute(StrRepQuery)

strFromDate = Format(DTPFromDate.Value, "dd-MMM-yyyy") & " " & Format(DTPFTime.Value, "HH:MM:SS")
strToDate = Format(DTPToDate.Value, "dd-MMM-yyyy") & " " & Format(DTPToTime.Value, "HH:MM:SS")

If RepRst.EOF = False Then

If Not IsNull(DTPFromDate.Value) And Not IsNull(DTPToDate.Value) Then
StrRepQuery = "SELECT *FROM TAGVALUE WHERE ParentID = " & RepRst!UID & " AND VALDATE >=#" & strFromDate & "# AND VALDATE <= #" & strToDate & "# ORDER BY VALDATE,VALTIME"
End If

End If

Exit Sub
ErrorHandler:
Exit Sub
End Sub

Private Sub CmdDMConductivity_Click()
If Validate = True Then Exit Sub
StrName = ""
StrName = "DM Water Conductivity"
Call RepQuary
SaveDataintoExcel
End Sub

Private Sub CmdDMSilica_Click()
If Validate = True Then Exit Sub
StrName = ""
StrName = "DM Water Silica"
Call RepQuary
SaveDataintoExcel
End Sub

Private Sub CmdDmWaterPH_Click()
If Validate = True Then Exit Sub
StrName = ""
StrName = "DM Water pH"
Call RepQuary
SaveDataintoExcel
End Sub

Private Sub CmdFile_Click()
On Error GoTo ErrorHandler
Dim FoldName As String, RowNo As Integer

CommonDialog1.ShowSave

FoldName = CommonDialog1.FileName
If FoldName = "" Then Exit Sub

If Len(FoldName) > 3 Then
If Right(FoldName, 4) <> ".xls" Then
FoldName = FoldName & ".xls"
End If
End If

txtFileName = FoldName
Exit Sub
ErrorHandler:
Exit Sub
End Sub

Private Sub CmdMBConductivity_Click()
If Validate = True Then Exit Sub
StrName = ""
StrName = "MB Conductivity"
Call RepQuary
SaveDataintoExcel
End Sub

Private Sub CmdMBpH_Click()
If Validate = True Then Exit Sub
StrName = ""
StrName = "MB pH"
Call RepQuary
SaveDataintoExcel
End Sub

Private Sub CmdORP_Click()
If Validate = True Then Exit Sub
StrName = ""
StrName = "ORP"
Call RepQuary
SaveDataintoExcel
End Sub

Private Sub CmdROA_Click()
If Validate = True Then Exit Sub
StrName = ""
StrName = "RO A Salt Passage"
Call RepQuary
SaveDataintoExcel
End Sub

Private Sub CmdROB_Click()
If Validate = True Then Exit Sub
StrName = ""
StrName = "RO B Salt Passage"
Call RepQuary
SaveDataintoExcel
End Sub

Private Sub CmdROC_Click()
If Validate = True Then Exit Sub
StrName = ""
StrName = "RO C Salt Passage"
Call RepQuary
SaveDataintoExcel
End Sub

Private Sub CmdWaterFlow_Click()
If Validate = True Then Exit Sub
StrName = ""
StrName = "DM Water Flow"
Call RepQuary
SaveDataintoExcel
End Sub

Private Sub CmdWaterPressure_Click()
If Validate = True Then Exit Sub
StrName = ""
StrName = "DM Water Pressure"
Call RepQuary
SaveDataintoExcel
End Sub

Private Sub Form_Load()

srv.Connect "RSLinx OPC Server"
Set grp = srv.OPCGroups.Add("AA")

''' grp.OPCItems.AddItem "[TOPICNAME]TagName1", 1
''' grp.OPCItems.AddItem "[TOPICNAME]TagName2", 2

'FOR DM WATER pH
grp.OPCItems.AddItem "[tisco_pri_mod_230607]F8:72", 1

'FOR DM WATER CONDUCTIVITY
grp.OPCItems.AddItem "[tisco_pri_mod_230607]F8:99", 2

'FOR DM WATER SILICA
grp.OPCItems.AddItem "[tisco_pri_mod_230607]F8:2", 3

'FOR DM WATER FLOW
grp.OPCItems.AddItem "[tisco_pri_mod_230607]F8:54", 4

'FOR DM WATER PRESSURE
grp.OPCItems.AddItem "[tisco_pri_mod_230607]F8:1", 5

'FOR RO A SALT PASSAGE
grp.OPCItems.AddItem "[tisco_pri_mod_230607]F8:164", 6
grp.OPCItems.AddItem "[tisco_pri_mod_230607]F8:163", 7

'FOR RO B SALT PASSAGE
grp.OPCItems.AddItem "[tisco_pri_mod_230607]F8:174", 8
grp.OPCItems.AddItem "[tisco_pri_mod_230607]F8:173", 9

'FOR RO C SALT PASSAGE
grp.OPCItems.AddItem "[tisco_pri_mod_230607]F8:184", 10
grp.OPCItems.AddItem "[tisco_pri_mod_230607]F8:183", 11

'FOR MB pH
grp.OPCItems.AddItem "[tisco_pri_mod_230607]F8:38", 12

'FOR MB Conductivity
grp.OPCItems.AddItem "[tisco_pri_mod_230607]F8:09", 13

'FOR ORP
grp.OPCItems.AddItem "[tisco_pri_mod_230607]F8:81", 14


'For Access DataBase Connectivity
Set Cn = New ADODB.Connection
Set Rst = New ADODB.Recordset
Set TempRst = New ADODB.Recordset
Cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\PLCDATA.MDB;Persist Security Info=False"

Cn.BeginTrans
Cn.Execute "Delete From TagValue Where ValDate<=#" & Format(Now - 100, "dd-MMM-yyyy") & "#"
Cn.CommitTrans

grp.IsActive = True
grp.IsSubscribed = True

DTPFTime.Value = "06:00:00 AM"
DTPToTime.Value = "06:00:00 PM"

End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim num As Integer
num = MsgBox("Are you sure want to close?.", vbInformation + vbYesNo, "PLC Report.")
If num = vbYes Then
Unload Me
Else
Cancel = 1
Exit Sub
End If
End Sub

Private Sub grp_DataChange(ByVal TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date)
'''For i = 1 To NumItems
'''
''' If ClientHandles(i) = 1 Then
''' MsgBox grp.OPCItems(1).Value
''' grp.OPCItems(1).Write (0)
''' End If
'''
''' If ClientHandles(i) = 2 Then
'''
''' End If
'''
'''Next
End Sub


Private Sub SaveDataintoExcel()
On Error GoTo ErrorHandler

Dim iR As Long
Dim iC As Long
Dim iCol As Long
Dim FromDate As String, ToDate As String
Dim xlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet


If txtFileName = "" And OptSave.Value = True Then
MsgBox "Enter Filename to save.", vbExclamation, "Information !"
Exit Sub
End If

Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.ActiveSheet

iCol = 1


FromDate = Format(DTPFromDate.Value, "dd-MMM-yyyy") & Space(3) & Format(DTPFTime.Value, "HH:MM") & "hr"
ToDate = Format(DTPToDate.Value, "dd-MMM-yyyy") & Space(3) & Format(DTPToTime.Value, "HH:MM") & "hr"

Set xlSheet = xlApp.ActiveSheet

xlSheet.Cells(1, 2) = "PLC Report For " & "(" & StrName & ")"
xlSheet.Cells(1, 2).Font.Bold = True

xlSheet.Cells(2, 2) = FromDate & " To " & ToDate
xlSheet.Cells(2, 2).Font.Bold = True

xlSheet.Cells(3, 2) = "----------------------------------------------------------------------------------------------"
xlSheet.Cells(4, 2) = "Date"
xlSheet.Cells(4, 2).Font.Bold = True
xlSheet.Cells(4, 4) = "Time(HR:Min)"
xlSheet.Cells(4, 4).Font.Bold = True
xlSheet.Cells(4, 6) = StrName
xlSheet.Cells(4, 6).Font.Bold = True
xlSheet.Cells(5, 2) = "----------------------------------------------------------------------------------------------"

Set Rst = Cn.Execute(StrRepQuery)
iR = 6
Do While Rst.EOF = False
xlSheet.Cells(iR, 2) = Format(Rst!ValDate, "dd-MMM-yyyy")
xlSheet.Cells(iR, 4) = Format(Rst!ValTime, "HH:MM")
xlSheet.Cells(iR, 6) = Rst!TagValue
iR = iR + 1
Rst.MoveNext
Loop

xlSheet.Cells(iR + 1, 2) = "----------------------------------------------------------------------------------------------"

For iC = 1 To iCol
xlSheet.Columns(iC).EntireColumn.AutoFit
Next

xlApp.Visible = True

If OptSave.Value = True Then
xlApp.ActiveWorkbook.SaveAs txtFileName.Text
txtFileName.Text = ""
Else
xlBook.Close
End If

Exit Sub
ErrorHandler:
MsgBox "Error"
txtFileName.Text = ""
Exit Sub
End Sub

Private Sub Timer1_Timer()
On Error GoTo ErrorHandler
Dim i, j As Integer
Dim ROANum1, ROANum2, ROANum3 As Double
Dim num As Double
num = 0

If Format(Now, "HH:MM:SS") = Format(Now, "HH:00:00") Or Format(Now, "HH:MM:SS") = Format(Now, "HH:10:00") Or Format(Now, "HH:MM:SS") = Format(Now, "HH:20:00") Or Format(Now, "HH:MM:SS") = Format(Now, "HH:30:00") Or Format(Now, "HH:MM:SS") = Format(Now, "HH:40:00") Or Format(Now, "HH:MM:SS") = Format(Now, "HH:50:00") Then

For i = 1 To 14
Cn.BeginTrans
Set TempRst = Cn.Execute("Select Max(UniqueID) as UID from Tagvalue")

If Not IsNull(TempRst!UID) Then
num = Val(TempRst!UID) + 1
Else
num = 1
End If

StrQuery = "insert into Tagvalue(UniqueID,ParentID,TagValue,ValDate,ValTime) values("

If i >= 1 And i < 6 Then
''StrQuery1 = "" & num & "," & i & "," & grp.OPCItems(i).Value & ",'" & Format(Now, "dd-MMM-yyyy") & "','" & Format(Now, "HH:NN:SS") & "')"
StrQuery1 = "" & num & "," & i & "," & grp.OPCItems(i).Value & ",'" & Now & "','" & Format(Now, "HH:NN:SS") & "')"


ElseIf i = 7 Then
ROANum1 = grp.OPCItems(i - 1).Value
ROANum2 = grp.OPCItems(i).Value
ROANum3 = (ROANum1 / ROANum2) * 100
''StrQuery1 = "" & num & "," & (i - 1) & "," & ROANum3 & ",'" & Format(Now, "dd-MMM-yyyy") & "','" & Format(Now, "HH:NN:SS") & "')"
StrQuery1 = "" & num & "," & (i - 1) & "," & ROANum3 & ",'" & Now & "','" & Format(Now, "HH:NN:SS") & "')"


ElseIf i = 9 Then
ROANum1 = grp.OPCItems(i - 1).Value
ROANum2 = grp.OPCItems(i).Value
ROANum3 = (ROANum1 / ROANum2) * 100
''StrQuery1 = "" & num & "," & (i - 2) & "," & ROANum3 & ",'" & Format(Now, "dd-MMM-yyyy") & "','" & Format(Now, "HH:NN:SS") & "')"
StrQuery1 = "" & num & "," & (i - 2) & "," & ROANum3 & ",'" & Now & "','" & Format(Now, "HH:NN:SS") & "')"

ElseIf i = 11 Then
ROANum1 = grp.OPCItems(i - 1).Value
ROANum2 = grp.OPCItems(i).Value
ROANum3 = (ROANum1 / ROANum2) * 100
''StrQuery1 = "" & num & "," & (i - 3) & "," & ROANum3 & ",'" & Format(Now, "dd-MMM-yyyy") & "','" & Format(Now, "HH:NN:SS") & "')"
StrQuery1 = "" & num & "," & (i - 3) & "," & ROANum3 & ",'" & Now & "','" & Format(Now, "HH:NN:SS") & "')"


ElseIf i >= 12 Then
''StrQuery1 = "" & num & "," & (i - 3) & "," & grp.OPCItems(i).Value & ",'" & Format(Now, "dd-MMM-yyyy") & "','" & Format(Now, "HH:NN:SS") & "')"
StrQuery1 = "" & num & "," & (i - 3) & "," & grp.OPCItems(i).Value & ",'" & Now & "','" & Format(Now, "HH:NN:SS") & "')"

Else
StrQuery1 = ""
End If

If StrQuery1 <> "" Then
StrQuery = StrQuery & StrQuery1
Cn.Execute (StrQuery)
End If

Cn.CommitTrans
Next
End If
Exit Sub
ErrorHandler:
Exit Sub
End Sub




Kindly suggest me the proper way and how to overcome the situation.
KK

GeneralRe: 1073479673(c0040007) Pin
Richard MacCutchan10-Nov-14 23:11
mveRichard MacCutchan10-Nov-14 23:11 
QuestionChecking listview Items against a lable text Pin
Pete_1237-Nov-14 10:41
Pete_1237-Nov-14 10:41 
NewsRe: Checking listview Items against a lable text Pin
Mycroft Holmes7-Nov-14 13:10
professionalMycroft Holmes7-Nov-14 13:10 
QuestionVBScript / HTA - Drop Down Menu in form Pin
Malbordio5-Nov-14 13:41
Malbordio5-Nov-14 13:41 
QuestionCapturing a Picturebox in Windows 8 Pin
gwittlock31-Oct-14 17:34
gwittlock31-Oct-14 17:34 
SuggestionRe: Capturing a Picturebox in Windows 8 Pin
Richard MacCutchan31-Oct-14 22:20
mveRichard MacCutchan31-Oct-14 22:20 
GeneralRe: Capturing a Picturebox in Windows 8 Pin
gwittlock31-Oct-14 23:55
gwittlock31-Oct-14 23:55 
GeneralRe: Capturing a Picturebox in Windows 8 Pin
Richard MacCutchan31-Oct-14 23:58
mveRichard MacCutchan31-Oct-14 23:58 
GeneralRe: Capturing a Picturebox in Windows 8 Pin
gwittlock1-Nov-14 0:03
gwittlock1-Nov-14 0:03 
GeneralRe: Capturing a Picturebox in Windows 8 Pin
Richard MacCutchan1-Nov-14 0:11
mveRichard MacCutchan1-Nov-14 0:11 
GeneralRe: Capturing a Picturebox in Windows 8 Pin
gwittlock1-Nov-14 0:22
gwittlock1-Nov-14 0:22 
GeneralRe: Capturing a Picturebox in Windows 8 Pin
Richard MacCutchan1-Nov-14 5:15
mveRichard MacCutchan1-Nov-14 5:15 
GeneralRe: Capturing a Picturebox in Windows 8 Pin
i006-Nov-14 13:08
i006-Nov-14 13:08 
GeneralRe: Capturing a Picturebox in Windows 8 Pin
Richard MacCutchan6-Nov-14 22:04
mveRichard MacCutchan6-Nov-14 22:04 
GeneralRe: Capturing a Picturebox in Windows 8 Pin
Mycroft Holmes1-Nov-14 0:12
professionalMycroft Holmes1-Nov-14 0:12 
GeneralRe: Capturing a Picturebox in Windows 8 Pin
gwittlock1-Nov-14 0:20
gwittlock1-Nov-14 0:20 
AnswerRe: Capturing a Picturebox in Windows 8 Pin
Dave Kreskowiak1-Nov-14 4:01
mveDave Kreskowiak1-Nov-14 4:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.