locked
Visual Basic 2010 Counter Code Problem

    Pregunta

  • Hi All

    I'm using Visual Basic 2010. I have a problem related to my code. My problem is I have my two PCs. They have counter software, with timer code on the first PC. The main problem is, when the counter software is stopped on first PC, the counter on the other computer should stop as well (without sql connection)

    Thanks in advance.

    miércoles, 26 de enero de 2011 13:11

Todas las respuestas

  • Hi,

    first of all I do not see a codeing problem. I see a design problem. How should the 2nd computer / the 2nd application see, that the first one was shuted down?

    So you need to decide, what common ressource you want to use to share this information. But only you have the knowledge about that.

    Common szenarios are:
    - Network connection between the systems (e.g. directly holding a connection between the 2 systems)
    - Shared File Space
    - low level on shared SCSI bus (I remember all this from fail over solutions :) )

    The normal pattern is, that you have a central ressource that is responsible. It could be a server application (file share, Database, ....)

    You know the possibilities. Tell us more and maybe we can help you more with a possible solution.

    With kind regards,

    Konrad

    miércoles, 26 de enero de 2011 20:41
  • If you want control two separate PC or their behavior concerning one program it is necessary to syncrone both pc.You will need any way of connection. This does not require a sql database but there must exist a common file. This could be a Ini-File.

    I see, I will mutate to a Ini pope inside this forum but since programmeres changed to My.Settings the advance of one common file for reading, writing and also controlling  has lost.

    But even such a ini file asks for connection. This can be that on PC works as server and the second one will be served by this terminal. Think about this and post more details of the way of communication.


    Liebe Grüße Stefan | Cheers Stefan I'm using VB 2008 Express
    miércoles, 26 de enero de 2011 23:11
  • Hi,

    First of all ,  thanks for your both your feedback. I want  TCP/IP communication protocol and intranet connection type between 2 systems.So ,I do not want  such a Fail over Solutions.Last, but not least  could be an ini-file   as common file .

    Thanks in advance.

    Cheers,

    jueves, 27 de enero de 2011 9:51
  • Any suggestions?
    viernes, 28 de enero de 2011 18:09
  • Hi,

    First of all ,  thanks for your both your feedback. I want  TCP/IP communication protocol and intranet connection type between 2 systems.So ,I do not want  such a Fail over Solutions.Last, but not least  could be an ini-file   as common file .

    Thanks in advance.

    Cheers,


    Well, you have already come up with a mechanism, so what, exactly is the problem?

    If you search the innernet, you'll find a whole host of TCP/IP projects which you can tailor to your needs.


    Stephen J Whiteley
    viernes, 28 de enero de 2011 18:12
  • Hi,

    First of all ,  thanks for your both your feedback. I want  TCP/IP communication protocol and intranet connection type between 2 systems.So ,I do not want  such a Fail over Solutions.Last, but not least  could be an ini-file   as common file .

    Thanks in advance.

    Cheers,


    Well, you have already come up with a mechanism, so what, exactly is the problem?

    If you search the innernet, you'll find a whole host of TCP/IP projects which you can tailor to your needs.


    Stephen J Whiteley
    have you example code in your hand? Cheers,
    sábado, 29 de enero de 2011 19:27
  • Hi systemselo,

     

    It is difficult to support you with so rare information. So I just give you an example for handling of INI-Files.

    Be aware for each value you want to store in the common file you'll need the stream reader and the stream writer. It is a lot of work to handle an manage a Ini-File because the smalest mistake will have a big effect.

    For your apps note that all application will need the correct information from ini-file:

    Where is it locadet
    Exaxt name

    Whene these informaton are correct declared your app can read and write to this file. Also override (change) settings. This can be an advancen when you change or adjust settings. Ic can be also a handicap when you change settings from application A which show also effect for application B which are not wished in this app.

    This takes a lot of time for each if else loop when you read the Ini-File. So is colul be you want to have a value e changable in app A but you like to use a fix value in app B. In this case your if then loop need to different which application starts reading ...

    I think, this is one of the reaseon why Ini-Files are not really attractive meanwhile. BUT, it is one possibility.

    Find now the example to store text from TextBox1 to your ini and read the ini.
    For a test you also can cange text by unsing a editor program. You'll see, it will work.

    Good luck

    Imports System.Runtime.InteropServices
    Imports System.Text
    Imports System.IO
    
    Public Class Form1
      'Ini-Deklaration
      Public Declare Function WritePrivateProfileString Lib "kernel32" _
      Alias "WritePrivateProfileStringA" ( _
      ByVal lpApplicationName As String, _
      ByVal lpKeyName As String, _
      ByVal lpString As String, _
      ByVal lpFileName As String) As Long
    
      Public Declare Function GetPrivateProfileString Lib "kernel32" _
       Alias "GetPrivateProfileStringA" ( _
       ByVal lpApplicationName As String, _
       ByVal lpKeyName As String, _
       ByVal lpDefault As String, _
       ByVal lpReturnedString As String, _
       ByVal nSize As Long, _
       ByVal lpFileName As String) As Long
    
      'warum auch immer, ohne diese Variante kommt eine Fehlermeldung
      Public Declare Auto Function GetPrivateProfileString Lib "kernel32" (ByVal lpAppName As String, _
            ByVal lpKeyName As String, _
            ByVal lpDefault As String, _
            ByVal lpReturnedString As StringBuilder, _
            ByVal nSize As Integer, _
            ByVal lpFileName As String) As Integer
      Sub Main()
        'Ende Ini-Deklaration
      End Sub
    
      Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    
        'Wert auslesen und als MessageBox ausgeben
        'Read from Ini-File
        Dim IniPfad As String = "C:\Test\"
        Dim IniName As String = "Test"
        Dim myTestIni As String = IniPfad & IniName & ".ini"
    
        Dim Specification As Integer
        Dim sbSpecification As StringBuilder  'StringBuilder für ns
        sbSpecification = New StringBuilder(500)    'NetSource
        Specification = GetPrivateProfileString("Theme", "Specification", "", sbSpecification, sbSpecification.Capacity, myTestIni)
        If sbSpecification.ToString <> Nothing Then
          MsgBox("Application has read """ & sbSpecification.ToString & """from " & myTestIni)
        Else
          MsgBox("No information, I'll correct this by standard settings", MsgBoxStyle.Exclamation)
          WritePrivateProfileString("Theme", "Specification", "Hello", myTestIni)
        End If
      End Sub
    
    
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Write to specified Ini-File
        Dim IniPfad As String = "C:\Test\"
        Dim IniName As String = "Test"
        Dim myTestIni As String = IniPfad & IniName & ".ini"
        WritePrivateProfileString("Theme", "Specification", Me.TextBox1.Text, myTestIni)
      End Sub
    End Class
    
    


    Liebe Grüße Stefan | Cheers Stefan I'm using VB 2008 Express
    domingo, 30 de enero de 2011 12:41