VB-Programm starten

Seite 1 von 1 - Forum: Coding Stuff auf overclockers.at

URL: https://www.overclockers.at/coding-stuff/vb-programm_starten_29630/page_1 - zur Vollversion wechseln!


jayjay schrieb am 26.03.2002 um 14:53

Wie lautet in Visual Basic der Befehl, um ein Programm zu starten (also ich klick auf Button-> Programm startet)

Ach ja, wenn ich grad dabei bin: wie kann man auf Knopfdruck eine bestimmte Textdatei öffnen?


JC schrieb am 26.03.2002 um 15:04

Entweder mit der Shell oder der AppActivate-Anweisung oder per API-Call.

Eine bestimmte Textdatei? Welche?


jayjay schrieb am 26.03.2002 um 15:07

Zitat von JC
Entweder mit der Shell oder der AppActivate-Anweisung oder per API-Call.

Eine bestimmte Textdatei? Welche?

Wie meinst welche Textdatei?????:confused:

Könnt ich bitte ein Beispiel haben für das Programm starten (mit den Begriffen Shell, AppActive Anweisung und API-Call kann ihc nicht wirklich was anfangen:rolleyes:


schrieb am 26.03.2002 um 15:11

beispiel für "in textdatei schreiben" - ist ein logging skript, das per aufruf eine zeile ins logfile hinzufügt.

Code: PHP
Public Sub Logging(strLogText)

Dim fso As FileSystemObject
Dim file As TextStream
Dim dtFileDate As String
Dim strFileName As String
Dim strTime As String

Set fso = New FileSystemObject

strFileName = "mylogfile.txt"

If (fso.FileExists(strFileName)) Then
   Set file = fso.OpenTextFile(strFileName, ForAppending)
Else
   Set file = fso.CreateTextFile(strFileName, False)
End If

strTime = Format(Now(), "hh:mm:ss AMPM")

file.WriteLine strTime & " // " & strLogText

Set file = Nothing
Set fso = Nothing

End Sub

edit: lustig find ich, dass er gewisse sachen im code-tag nicht anzeigt: zB das End Sub, und auch backslashes...

naja, der VB compiler schreit eh, wenn was fehlt :p


JC schrieb am 26.03.2002 um 15:12

Hast die Hilfe wohl auch nicht installiert?

Ich hab hier's VB ned da, aber es dürfte in etwa so ablaufen:

shell Datei incl. Pfad as String, Parameter für Window-State (minimized, maximized, hidden, ...)

appactivate "titel der anwendung (steht in der titlebar)

Diese luschigen Funktionen benutze ich schon lange nicht mehr, da gibt's auch keine haftung für richtigkeit von meiner seite.


jayjay schrieb am 26.03.2002 um 15:19

@rettich: danke, ist glaub ich etwas zu viel, dass du da geschrieben hast, aber danke, ich schaus mir mal an

@JC: Ich hab schon die Hilfe, aber ich wusste nicht genau, nach was ich suche, jetzt da ich weiß, dass ich nach shell suchen soll, hab ichs auch gefunden, danke


jayjay schrieb am 26.03.2002 um 15:32

Zitat von rettich
Dim fso As FileSystemObject

Set fso = New FileSystemObject

If (fso.FileExists(strFileName)) Then
Set file = fso.OpenTextFile(strFileName, ForAppending)
End If
[/php]

filesystemobjekt gibts im VB nicht :(


JC schrieb am 26.03.2002 um 15:37

Projekt -- Verweise, hinzufügen, fertig.


jayjay schrieb am 26.03.2002 um 16:00

noch eine Frage: Wie kann ich erzwingen, dass das Programm immer im Vordergrund bleibt?
Also wenn ich auf Knöpfchen drücke, startet sich ein Programm, und das VB-Programm bleibt aber im Vordergrund


JC schrieb am 26.03.2002 um 16:18

Du meinst, dass es immer im Vordergrund bleibt? So wie Winamp, bei drücken der Tasten Strg+A?

Only by API-Call.


jayjay schrieb am 26.03.2002 um 16:24

Zitat von JC
Du meinst, dass es immer im Vordergrund bleibt? So wie Winamp, bei drücken der Tasten Strg+A?

Only by API-Call.

Ja, meine ich, wie mach ich das mit API-Call, was is so besonderes an API-Call, und wie verwend ich das


JC schrieb am 26.03.2002 um 16:28

Zitat von jayjay
Ja, meine ich, wie mach ich das mit API-Call, was is so besonderes an API-Call, und wie verwend ich das
*rofl*
Schau dir doch bitte mal an, was API ist, bevor du das verwenden willst. Bei unsachgemäßer Verwendung schießt den PC bzw. VB öfter ab, als dir lieb ist.

aber bitte.

Code:
Option Explicit 

Private Const SWP_NOMOVE = 2 
Private Const SWP_NOSIZE = 1 
Private Const HWND_TOPMOST = -1 
Private Const HWND_NOTOPMOST = -2 
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE 

Private Declare Function SetWindowPos Lib "user32" _ 
      (ByVal hWnd As Long, _ 
      ByVal hWndInsertAfter As Long, _ 
      ByVal x As Long, _ 
      ByVal y As Long, _ 
      ByVal cx As Long, _ 
      ByVal cy As Long, _ 
      ByVal wFlags As Long) As Long 


Public Function SetTopMostWindow(hWnd As Long, Topmost As Boolean) As Long 
    ' Function sets a window as always on top, or turns this off 
      
    ' hwnd - handle the the window to affect 
    ' Topmost - do you want it always on top or not 
     
   On Error GoTo ErrHandler 
     
   If Topmost = True Then 'Make the window topmost 
      SetTopMostWindow = SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS) 
   Else 
      SetTopMostWindow = SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS) 
      'SetTopMostWindow = SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, FLAGS) 
      SetTopMostWindow = False 
   End If 
      
    Exit Function 
ErrHandler: 
    Select Case Err.Number 
        Case Else 
            Err.Raise Err.Number, Err.Source & "+modAPIStuff/SetTopMostWindow", Err.Description 
    End Select 
End Function 

Private Sub Form_Load() 
    SetTopMostWindow Me.hWnd, True 
End Sub 

EDIT
Ist BTW auch ein nettes Beispiel für's Error-Handling, obwohl mir Try... Catch... Finally im Dot Net besser gefällt.




overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2026