Vai al contenuto
PLC Forum


Codice Vb6 Per Scrivere In Una Tag Di Rsviewstudio


Messaggi consigliati

Inserito:

Ho realizzato un applicativo per recuperare dei dati da un database Access. Il mio attuale problema è come scrivere i valori letti da Access dentro a delle tag di un applicativo Stand Alone di RSView Studio 4.0

All'interno del VBA di RSView studio si riesce a leggere e scrivere le tag creando un ogetto TagGroup e aggiungendo le tag che interessano per poi usarle tramite codice: ho provato lo stesso con il mio applicativo VB6 ma non sono riuscito, forse sbaglio nello scrivere il codice forse la strada da seguire è un'altra.

Dal momento che si tratta di poche righe di codice da scrivere, ma nel modo corretto, c'è qualcuno che mi può dare una mano???

Virginio


Inserita:

Sono riuscito a trovare la soluzione, se qualcuno fosse interessato all'argomento occorre scrivere il seguente codice valido per una tag di prova:

Sub SetUpTagGroup()

Dim oCl As Application

On Error Resume Next

Err.Clear

If oCl Is Nothing Then

Set oCl = displayclient.Application

End If

If oGroup Is Nothing Then

Set oGroup = oCl.CreateTagGroup("/", 500)

If Err.Number Then

LogDiagnosticsMessage "Error creating TagGroup. Error: " & Err.Description, ftDiagSeverityError

Exit Sub

End If

oGroup.Add "TEST_TAG"

oGroup.Active = True

End If

End Sub

Sub SetTagValue()

On Error Resume Next

Dim oTag As Tag

If Not oGroup Is Nothing Then

Set oTag = oGroup.Item("TEST_TAG")

Err.Clear

oTag.Value = 10

' Test the Error number for the result.

Select Case Err.Number

Case 0:

' Write completed successfully... log a message

LogDiagnosticsMessage "Write to tag " & oTag.Name & " was successful."

Case tagErrorReadOnlyAccess:

MsgBox "Unable to write tag value. Client is read-only."

Case tagErrorWriteValue:

If oTag.LastErrorNumber = tagErrorInvalidSecurity Then

MsgBox "Unable to write tag value. The current user does not have security rights."

Else

MsgBox "Error writing tag value. Error: " & oTag.LastErrorString

End If

Case tagErrorOperationFailed:

MsgBox "Failed to write to tag. Error: " & Err.Description

End Select

End If

End Sub

  • 3 weeks later...
Inserita:

è molto più semplice....

Basta che tra i Reference hai selezionato RSModel, ora in VBA crei oggetti

Questo è un esempio che avevo fatto come prova tempo fa, per importare delle cose da MySQL e passarle ad un TAG....c'è molto da tagliare come vedrai...

Sub main()

Dim AllTags As Tags

Dim SingleTag As Tag

Set AllTags = gTagDb.QueryForTags("AccessFiles\folder\*")

Dim Risultato As ADODB.Recordset

Dim conn As ADODB.Connection

Dim comSQL As ADODB.Command

Dim querySQL As String

Dim mess As String

Dim nrow As Integer

Set conn = New ADODB.Connection

conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=127.0.0.1;DATABASE=Bolton;UID=root;PWD=261281;"

conn.Open

Set Risultato = New ADODB.Recordset

Risultato.Open "SELECT * FROM mp;", conn

Do While Not Risultato.EOF

mess = Risultato!Nome

Set SingleTag = gTagDb.GetTag("pippo\nuovastringa")

SingleTag.Value = mess

MsgBox mess

Risultato.MoveNext

Loop

Risultato.Close

conn.Close

Set Risultato = Nothing

Set conn = Nothing

End Sub

Crea un account o accedi per commentare

Devi essere un utente per poter lasciare un commento

Crea un account

Registrati per un nuovo account nella nostra comunità. è facile!

Registra un nuovo account

Accedi

Hai già un account? Accedi qui.

Accedi ora
×
×
  • Crea nuovo/a...