Der er ikke nogen fejl i sidste linie. En tekst boks har to properties : Text og SelText. Text er den tekst der står i tekstboksen. SelText er den markerede tekst eller insertion point i teksten.
jeg er ved at lave en HTML editor og vil lave en menupunkt som sætter en "last update" dato/tid ind. nu har jeg læst hjælp filen igennem fra ende til anden og prøvet ALLE eksemplerne og har fået hjælp til det... alle der har forsøgt at hjælpe mig har givet op. det kan da ikke være så svært at insætte den nuværende tid og dato.
Dim fil As String Dim tmp As String Dim tmpLine$ Dim nFilenumber% Dim savestat As String Dim brugersti As String Const maxUndo = 50 'Maximum num of undos Dim gintIndex As Integer Dim gblnIgnoreChange As Boolean Dim gstrStack(maxUndo) As String Dim stackBK(maxUndo) As String Dim path As String Dim web As Form1
Private Sub br_Click() Clipboard.SetText "<br>" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub center_Click() Clipboard.SetText "<p align=center>" & Text1.SelText & "</p>" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub Command1_Click() Clipboard.SetText "<p align=left>" & Text1.SelText & "</p>" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub Command12_Click() Clipboard.SetText "<HR>" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub Command13_Click() Clipboard.SetText "<!-- " & Text1.SelText & " -->" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub Command2_Click() Clipboard.SetText "<p align=center>" & Text1.SelText & "</p>" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub Command3_Click() Clipboard.SetText "<p align=right>" & Text1.SelText & "</p>" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub Command5_Click() Clipboard.SetText "<br>" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub Command6_Click() Unload Me End Sub
Private Sub Comment_Click() Clipboard.SetText "<!-- " & Text1.SelText & " -->" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub copy_Click() Clipboard.SetText Text1.SelText End Sub
Private Sub copyx_Click() If Text1.SelText > "" Then Form2.List1.AddItem Text1.SelText End If End Sub
Private Sub cut_Click() Clipboard.SetText Text1.SelText Text1.SelText = "" End Sub
Private Sub cutx_Click() If Text1.SelText > "" Then Form2.List1.AddItem Text1.SelText End If Text1.SelText = "" End Sub
Private Sub delete_Click() Clipboard.SetText "" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub Dir1_Change() File1.FileName = Dir1.path End Sub
Private Sub Drive1_Change() Dir1.path = Drive1.Drive End Sub
Private Sub File1_Click() If savestat = "" Then Dim cancel As Integer Dim Msg1 ' Declare variable. ' Set the message text. Msg1 = "You havent saved your document. Do you want to save before you exit the application?" ' If user clicks the No button, stop QueryUnload. If MsgBox(Msg1, vbQuestion + vbYesNo, Me.Caption) = vbYes Then GoTo cancel End If Text1.Text = " " nFilenumber = FreeFile fil = Dir1.path & "\" & File1.FileName Open fil For Input As #nFilenumber Do While Not EOF(nFilenumber) Input #nFilenumber, tmpLine Text1.Text = Text1.Text & tmpLine & vbCrLf Loop Close #nFilenumber Label1.Caption = Dir1.path & "\" & File1.FileName cancel: End Sub
Private Sub Form_Load() File1.FileName = "*.html;*.htm;*.php;*.css;*.asp" savestat = "saved" path = "c:\" & "tmp.htm" End Sub
Private Sub Form_QueryUnload(cancel As Integer, UnloadMode As Integer) If UnloadMode = 0 Then If savestat = "saved" Then End Else Dim Msg1 ' Declare variable. ' Set the message text. Msg1 = "You havent saved your document. Do you want to save before you exit the application?" ' If user clicks the No button, stop QueryUnload. If MsgBox(Msg1, vbQuestion + vbYesNo, Me.Caption) = vbYes Then cancel = True End If End If If UnloadMode = 1 Then If savestat = "saved" Then End Else Dim Msg2 ' Declare variable. ' Set the message text. Msg2 = "You havent saved your document. Do you want to save before you exit the application?" ' If user clicks the No button, stop QueryUnload. If MsgBox(Msg2, vbQuestion + vbYesNo, Me.Caption) = vbYes Then cancel = True End If End If
If UnloadMode = 2 Then If savestat = "saved" Then End Else Dim Msg3 ' Declare variable. ' Set the message text. Msg3 = "You havent saved your document. Do you want to save before you exit the application?" ' If user clicks the No button, stop QueryUnload. If MsgBox(Msg3, vbQuestion + vbYesNo, Me.Caption) = vbYes Then cancel = True End If End If If UnloadMode = 3 Then If savestat = "saved" Then End Else Dim Msg4 ' Declare variable. ' Set the message text. Msg4 = "You havent saved your document. Do you want to save before you exit the application?" ' If user clicks the No button, stop QueryUnload. If MsgBox(Msg4, vbQuestion + vbYesNo, Me.Caption) = vbYes Then cancel = True End If End If If UnloadMode = 4 Then If savestat = "saved" Then End Else Dim Msg5 ' Declare variable. ' Set the message text. Msg5 = "You havent saved your document. Do you want to save before you exit the application?" ' If user clicks the No button, stop QueryUnload. If MsgBox(Msg5, vbQuestion + vbYesNo, Me.Caption) = vbYes Then cancel = True End If End If If UnloadMode = 5 Then If savestat = "saved" Then End Else Dim Msg6 ' Declare variable. ' Set the message text. Msg6 = "You havent saved your document. Do you want to save before you exit the application?" ' If user clicks the No button, stop QueryUnload. If MsgBox(Msg6, vbQuestion + vbYesNo, Me.Caption) = vbYes Then cancel = True End If End If
End Sub
Private Sub hr_Click() Clipboard.SetText "<HR>" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub left_Click() Clipboard.SetText "<p align=left>" & Text1.SelText & "</p>" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
If savestat = "" Then Dim cancel As Integer Dim Msg1 ' Declare variable. ' Set the message text. Msg1 = "You havent saved your document. Do you want to save before you exit the application?" ' If user clicks the No button, stop QueryUnload. If MsgBox(Msg1, vbQuestion + vbYesNo, Me.Caption) = vbYes Then GoTo cancel End If
On Error GoTo trap CommonDialog1.Filter = "Web Files|*.html;*.htm;*.php;*.css;*.asp" CommonDialog1.ShowOpen Label1.Caption = CommonDialog1.FileName Text1.SetFocus brugersti = Label1.Caption Text1.Text = "" nFilenumber = FreeFile Open brugersti For Input As #nFilenumber Do While Not EOF(nFilenumber) Input #nFilenumber, tmpLine Text1.Text = Text1.Text & tmpLine & vbCrLf Loop Close #nFilenumber savestat = "saved" cancel: trap: End Sub
Private Sub paste_Click() Text1.SelText = Clipboard.GetText End Sub
Private Sub pastex_Click() Form2.left = GetX * 15 Form2.Top = GetY * 15 Form2.Show End Sub
Private Sub pharse_Click() Clipboard.SetText "<p>" & Text1.SelText & "</p>" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub pre_Click() Clipboard.SetText "<PRE>" & Text1.SelText & "</PRE>" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub print_Click() Dim BeginPage, EndPage, NumCopies, Orientation, i ' Set Cancel to True. CommonDialog2.CancelError = True On Error GoTo ErrHandler ' Display the Print dialog box. CommonDialog2.ShowPrinter ' Get user-selected values from the dialog box. BeginPage = CommonDialog2.FromPage EndPage = CommonDialog2.ToPage NumCopies = CommonDialog2.Copies Orientation = CommonDialog2.Orientation For i = 1 To NumCopies
Printer.Print 'vækker printeren af dvale Printer.FontName = "Times New Roman" 'sætter skriftsnit Printer.FontSize = 12 'sætter skriftstørrelse Printer.Print "" 'skriver tom linie Printer.Print Tab(16); Text1.Text 'skriver indholdet med margin i 1. linie Printer.EndDoc 'starter udskrift
Next Exit Sub ErrHandler: ' User pressed Cancel button. Exit Sub End Sub
Private Sub quit_Click() Unload Me End Sub
Private Sub redo_Click() 'This is the basic redo stuff. If gintIndex < maxUndo Then ' max undo level is reached, do not redo gblnIgnoreChange = True gintIndex = gintIndex + 1 On Error Resume Next Text1.TextRTF = gstrStack(gintIndex) gblnIgnoreChange = False End If
End Sub
Private Sub right_Click() Clipboard.SetText "<p align=right>" & Text1.SelText & "</p>" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub save_Click() If tmp = "" Then tmp = FreeFile If Label1.Caption = "" Then Call saveas_Click Else Open Label1.Caption For Output As #tmp Print #tmp, Text1.Text Close #tmp tmp = "" savestat = "saved" End If Else Call saveas_Click End If
End Sub
Private Sub saveas_Click() On Error GoTo trap Dim save2 As String CommonDialog1.Filter = "Web Files|*.html;*.htm;*.php;*.css;*.asp" CommonDialog1.ShowSave save2 = CommonDialog1.FileName nFilenumber = FreeFile Open save2 For Output As #nFilenumber Print #nFilenumber, Text1.Text Close #nFilenumber savestat = "saved" trap: End Sub
Private Sub selall_Click() 'Sets the cursors position to zero Text1.SelStart = 0 'Selects the full length of rtfText Text1.SelLength = Len(Text1.Text) 'Sets the Focus to rtfText Text1.SetFocus End Sub
Private Sub space_Click() Clipboard.SetText " " Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub Text1_Change() savestat = "" 'Counter varibles, names have no meaning Dim g As Integer Dim b As Integer Dim i As Integer
g = maxUndo 'Initialize this to the max number of undos
If Not gblnIgnoreChange Then gintIndex = gintIndex + 1
If gintIndex >= maxUndo + 1 Then 'If > max num of undos reached
For b = 0 To maxUndo 'Copy the undo info to a backup array stackBK(b) = gstrStack(b) Next b
For i = 0 To maxUndo 'Copy the backup array info back to the original, but in a different order If g >= 1 Then g = g - 1 gstrStack(g) = stackBK(g + 1) 'gstrstack(49) = stackBK(50) get it?? End If Next i
gintIndex = maxUndo 'Set it to the max number of undos
End If gstrStack(gintIndex) = Text1.TextRTF End If
End Sub
Private Sub time_Click() 'Dim strTime As String 'strTime = format(now, "m/d/yy h:mm") 'Clipboard.SetText strTime 'Text1.SelText = Clipboard.GetText 'Clipboard.Clear 'Dim strTime As String 'strTime = format(now, "m/d/yy h:mm") 'Text1.SelText = strTime 'Dim strTime As String 'strTime = format(now, "m/d/yy h:mm") 'Text1.Text = strTime Text1.Text = format(now(), "m/d/yy h:mm") End Sub
Private Sub tt_Click() Clipboard.SetText "<TT>" & Text1.SelText & "</TT>" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub undo_Click() 'This says that if the Index is = to 0, then It shouldn't undo anymore If gintIndex = 0 Then Exit Sub
'This is the basic undo stuff. gblnIgnoreChange = True gintIndex = gintIndex - 1 On Error Resume Next Text1.TextRTF = gstrStack(gintIndex) gblnIgnoreChange = False
End Sub
Function SaveFile(file As String, t As TextBox) As Boolean tmp = FreeFile Open "c:\" & "tmp.htm" For Output As #tmp Print #tmp, Text1.Text Close #tmp End Function
Private Sub special()
'<!-- WebWriter AutoDato -->Opdateret d. 16.12.2002<!-- WW -->
End Sub
Private Sub view_Click() If Text1.Visible = True Then Text2.Text = Text1.Text WebBrowser1.Visible = True Text1.Visible = False Command4.Enabled = False Command5.Enabled = True SaveFile path, Text2 Set web = Form1 web.Show web.WebBrowser1.Navigate path web.SetFocus Else WebBrowser1.Visible = False Text1.Visible = True End If End Sub
Private Sub æ_Click() Clipboard.SetText "æ" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub ø_Click() Clipboard.SetText "ø" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Private Sub å_Click() Clipboard.SetText "å" Text1.SelText = Clipboard.GetText Clipboard.Clear End Sub
Problemet er at Format er et reserveret ord og menu-editoren laver åbenbart en skjult rutine der fyres ved klik på et menupunkt. Du kan selvfølgelig også præfixe med et eller andet (som det er god skik ved programmering) f.eks. mnuFormat.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.