Een bepaalde tekst anders afsluiten

Status
Niet open voor verdere reacties.

Schipperjte

Gebruiker
Lid geworden
24 jan 2006
Berichten
212
Ik probeer een tekst naar excel schrijven en eigenlijk een controle dat dit niet veranderd kan worden.

Zoek iets wat als de naam veranderd wordt in excel het programma afsluit

maar dit werkt niet. De naam moet Voerendaal zijn ,als dit veranderd wordt op het excel bestand dan moet hij het programma afsluiten



Code:
  If TextBox2.Text = ("Voerendaal") Then

        End If

        If TextBox2.Text = Not ("Voerendaal") Then
            Close()
        End If
 
Zo iets?

Code:
If TextBox2.Text = "Voerendaal" Then
        Exit sub
       ElseIf TextBox2.Text = TextBox2.Text Then
            Close()
        End If
 
Het werkt, maar dan alleen als ik in textbox klik om wat in te vullen .Met deze code haal ik de text op.

Wat doe ik nu om het altijd te laten controleren.

Als ik van het programma naar excel schrijf zie ik gelijk in excel wat ik letter voor letter schrijf.
In textbox 2 zie ik alleen de tekst komen in 1 keer als ik op de textbox wat wil invullen

Code:
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
        TextBox2.Text = Worksheets("een").Cells(15, 5).text
        If TextBox2.Text = "Voerendaal" Then
            Exit Sub
        ElseIf TextBox2.Text = TextBox2.Text Then
            Close()
        End If

    End Sub
 
Hangt van het moment dat je wild controleren af. bij opstarten set het in form_load
en op die plek waar je wild dat het word gecontroleerd.
maar maak er dan een Function van dat is netter.

Code:
  Function Voerendaal_Control As Boolean
TextBox2.Text = Worksheets("een").Cells(15, 5).text
        If TextBox2.Text = "Voerendaal" Then
            Exit Sub
        ElseIf TextBox2.Text = TextBox2.Text Then
            Close()
        End If

 End Function

en op de plaats waar je wild dat er gecontroleerd word bv.
Code:
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
 Voerendaal_Control()       
End Sub
 
Ok , alleen nog 1 probleempje

Als ik de tekst verander in het excel document en ik enter niet.
Dus ik sta nog in de cel dan slaat hij vast als ik control gebruik.


Kan ik dan iets invoeren bv on error resume next ofzo

Code:
System.Runtime.InteropServices.COMException was unhandled
  ErrorCode=-2147418111
  Message=Aanroep geweigerd door aangeroepene. (Uitzondering van HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))
  Source=Microsoft.VisualBasic
  StackTrace:
       bij Microsoft.VisualBasic.CompilerServices.LateBinding.LateIndexGet(Object o, Object[] args, String[] paramnames)
       bij Microsoft.VisualBasic.CompilerServices.NewLateBinding.InternalLateIndexGet(Object Instance, Object[] Arguments, String[] ArgumentNames, Boolean ReportErrors, ResolutionFailure& Failure)
       bij Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateIndexGet(Object Instance, Object[] Arguments, String[] ArgumentNames)
       bij textbox_refresh.Form1.Timer1_Tick(Object sender, EventArgs e) in c:\users\joshua\documents\visual studio 2010\Projects\textbox refresh\textbox refresh\Form1.vb:regel 35
       bij System.Windows.Forms.Timer.OnTick(EventArgs e)
       bij System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
       bij System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       bij System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       bij System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       bij System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       bij System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       bij System.Windows.Forms.Application.Run(ApplicationContext context)
       bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       bij textbox_refresh.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:regel 81
       bij System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       bij System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       bij Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       bij System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       bij System.Threading.ThreadHelper.ThreadStart()
  InnerException:
 
Probeer het met

Try
'Hier je opdracht
Catch ex As Exception
MsgBox(ex.ToString)
End Try
 
Bedankt het werkt.

Try en catch gaat beter
Heb het gecombineerd met een timer.

Bij timer 2 laat ik hem controleren.

Code:
 Private Worksheets As Object
    Public Sub New()



        InitializeComponent()
        Dim AppExcel As Object
        Dim workBook As Object
        AppExcel = CreateObject("Excel.Application")


        workBook = AppExcel.Workbooks.Open(My.Application.Info.DirectoryPath & "\een.xls")
        AppExcel.Visible = True
        Worksheets = workBook.worksheets
        Worksheets("een").Cells(15, 5).value = Label1.text

   




    End Sub
  
 
 

   
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Start()

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
     
        If ProgressBar1.Value <= 99 Then
            ProgressBar1.Value = ProgressBar1.Value + 1


        Else
            Timer2.Start()
            Timer1.Stop()
        End If
    End Sub

    'Bij timer2.tick:
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Try
            If ProgressBar1.Value = 50 Then TextBox2.Text = Worksheets("een").Cells(15, 5).text()


        Catch

            Timer2.Stop()
            MsgBox("U bent onbevoegd.")
            Close()
        End Try
        If ProgressBar1.Value >= 1 Then
            ProgressBar1.Value = ProgressBar1.Value - 1

        Else
            Timer1.Start()
            Timer2.Stop()
        End If
    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

        If TextBox2.Text = "Voerendaal" Then
            Exit Sub
        ElseIf TextBox2.Text = TextBox2.Text Then

            MsgBox("Je bent niet bevoegd om dit programma te gebruiken.")
            Close()
        End If
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Worksheets("een").Cells(1, 5).Value = TextBox1.Text
    End Sub
End Class
 
Alleen nog 1 vraagje.

Wat zet ik neer om 2 waarde's te stellen

bv Voerendaal of VOERENDAAL ?

Onderstaande tekst werkt niet


Code:
 If TextBox2.Text = "Voerendaal" or  "VOERENDAAL" Then


            Exit Sub
 
ik dacht zo iets

If TextBox2.Text = "Voerendaal" or TextBox2.Text = "VOERENDAAL" Then
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan