I'm trying to accept a backspace input as a character - visual-studio

I'm writing a program in visual basic 2015 to add users to the school server. I have text box's, that aren't editable, to display input from other text boxes. Sounds more complicated than it is, but the text boxes simply show your entries, so a lot will be completed without having to double up on entries. As the input changes on an input textbox, it updates to the display. However, I cannot detect a backspace input to update the displayed content. Is there a way to do this?
Here's a sample of the code.
Private Sub dp_TextChanged(sender As Object, e As EventArgs) Handles dp.TextChanged
If dp.Text = "" Then GoTo line1
i = Asc(dp.Text)
If i = 8 Then
domainp.Text = domainp.Text.Remove(domainp.Text.Length - 1)
End If
If dp.Text = "" Or dp.Text = " " Or dp.Text = "." Then GoTo line1
domainp.Text = domainp.Text & dp.Text
domain_prefix = domainp.Text
dp.Text = ""
i = 0
line1:
End Sub
I haven't programmed for years and have forgotten a LOT of things. I would appreciate any help you could give me.
I am using visual studio 2015

Use the KeyDown event. This will capture any type, backspace, or arrow key movement.

Related

marquee text on status bar in vb 6.0

I am developing new vb 6 application, I want to display a scrolling text (marquee)
on a status bar like news Line text I already have two panels used and now in the
third panel I want to use marquee.
I have done following but text is scrolling from middle of the panel it should be
scrolled from the right end to left end continuously.
Dim i As Byte
dim txtSample As String
txtSample = " - - - MARQUEE TEXT - - - "
Private Sub Timer1_Timer()
i = i + 1
StatusBar1.Panels(3).Text = Mid(txtSample, i)
If i > Len(txtSample) Then i = 1
End Sub
You code is actually correct but you are actually reducing the content in a rapid manner makes it a marquee. So to make it start from far edge instead from the length of your string, you have to buffer your string with space to cover the whole panel visible area.. something like this should do
txtSample = Space(150) & "- - - MARQUEE TEXT - - - "

vb6 use same button on 2 textbox

Hi our instructor asked us to create a calculator that only uses button
for the value input in, It should have enter value1 on 1st textbox and then the other value on the next textbox in vb6
is there a way to use the same button to enter a value on the next textbox?
lets say after you press button 3 it will show on textbox1
Text1.Text = "3"
my problem is it wont go to the next textbox after it show the number 3
I've already tried
If Text2.Setfoucs = True Then
Text2.Text = "3"
Else
Text1.Text = "3"
End If
Its giving me error.
I just wanted to use the same button on the second textbox
after it was used on the 1st textbox
I thought of using another bunch of buttons and set visible = true after the
1st button was pressed so that the nextone will be
Text2.Text = "3"
Im just a beginner on VB6 any suggestions will be greatly appreciated.
here is what the project looks like
http://i.imgur.com/ixK9s1U.png
setFocus is a function, not a variable, and it doesn't return a value, so you can't use it in an if clause.
Here is my suggestion to accomplish what you're trying to do:
Add a GotFocus event to each of your textboxes, that sets a variable. Like so:
Private selectedTxtBox As Integer
Private Sub Text1_GotFocus()
selectedTxtBox = 1
End Sub
Private Sub Text2_GotFocus()
selectedTxtBox = 2
End Sub
Then on your button, you can do:
If selectedTxtBox = 1 Then
Text1.Text = "3"
ElseIf selectedTxtBox = 2 Then
Text2.Text = "3"
End If

"New Scope" Macro for Visual Studio

I'm trying to create a new macro that takes the currently selected text and puts curly braces around it (after making a newline), while, of course, indenting as needed.
So, for example, if the user selects the code x = 0; and runs the macro in the following code:
if (x != 0) x = 0;
It should turn into:
if (x != 0)
{
x = 0;
}
(Snippets don't help here, because this also needs to work for non-supported source code.)
Could someone help me figure out how to do the indentation and the newlines correctly? This is what I have:
Public Sub NewScope()
Dim textDoc As TextDocument = _
CType(DTE.ActiveDocument.Object("TextDocument"), TextDocument)
textDoc.???
End Sub
but how do I figure out the current indentation and make a newline?
Sub BracketAndIndent()
Dim selection = CType(DTE.ActiveDocument.Selection, TextSelection)
' here's the text we want to insert
Dim text As String = selection.Text
' bracket the selection;
selection.Delete()
' remember where we start
Dim start As Integer = selection.ActivePoint.AbsoluteCharOffset
selection.NewLine()
selection.Text = "{"
selection.NewLine()
selection.Insert(text)
selection.NewLine()
selection.Text = "}"
' this is the position after the bracket
Dim endPos As Integer = selection.ActivePoint.AbsoluteCharOffset
' select the whole thing, including the brackets
selection.CharLeft(True, endPos - start)
' reformat the selection according to the language's rules
DTE.ExecuteCommand("Edit.FormatSelection")
End Sub
textDoc.Selection.Text = "\n{\n\t" + textDoc.Selection.Text + "\n}\n"
Of course the amount of \t before the { and } and Selection depend on the current indention.
Since there is a difference between selected Text and Document data, it's hard to find out where the cursor is within the document's data (at least in Outlook it is).
The only way I figured out how to do this in Outlook is to actually move the selection backwards until I got text that I needed, but that resulted in undesirable effects.
Try taking the selection start, and using that position in the document text, looking at that line and getting the amount of tabs.
I would think there wouldn't be formatting characters in VStudio.

How to call a visio macro from a stencil

i have written some Macros for Visio. Now I copied these to a Stencil called Macros.vss
How can I call my Macros now?
It all depends on what the macros do and how you'd like to call them. I'm going to assume they're simply macros that will execute something within the active Visio page.
By default in Visio VBA, any public subs with no arguments get added to the Visio Tools->Macros menu, in a folder named by the document holding the macros (in this case Macros) and then separated into folders by module name. If you're the only person using the macros then you probably don't need to do anything else.
However, since you put them in a vss file I'll assume you'd like to distribute them to other people.
There's something funny (and by funny I mean irritating) about Visio and how toolbars and buttons work, when added programmatically. Unfortunately, when you create a toolbar using the UIObject and Toolbar and ToolbarItem classes, Visio is going to assume the code you're calling resides in the active drawing, and cannot be in a stencil. So I can give you a little guidance on using those classes, but basically it consists of distributing a .vst template along with your .vss files, with just a single required sub in the .vst file.
So, instead of using a custom toolbar, you can attach code to shape masters in your .vss file that execute the code when they get dropped on a drawing document (using CALLTHIS and the EventDrop event in the shapesheet). With this method I just have a sub that gets called using callthis that takes a shape object as an argument, executes some code, then deletes the shape (if I don't want it around anymore).
And lastly, you can manipulate the Visio UI programmatically to add a toolbar and buttons for your macros. Below is some sample code, basically the way I do it with a solution I developed. As I mentioned above, the most important part of using this method is to have a document template (.vst) that holds a sub (with the below code it must be named RunStencilMacro) that takes a string as an argument. This string should be the "DocumentName.ModuleName.SubName". This sub must take the DocumentName out of the string, and get a Document object handle to that document. Then it must do ExecuteLine on that document with the ModuleName.SubName portion. You'll have to step through the code and figure some things out, but once you get the hang of what's going on it should make sense.
I'm not sure of any other ways to execute the macros interactively with VBA. I think exe and COM addons may not have this issue with toolbars...
Private Sub ExampleUI()
Dim UI As Visio.UIObject
Dim ToolbarSet As Visio.ToolbarSet
Dim Toolbars As Visio.Toolbars
Dim Toolbar As Visio.Toolbar
Dim ToolbarItems As Visio.ToolbarItems
Dim ToolbarItem As Visio.ToolbarItem
Dim TotalToolBars As Integer
Dim Toolbarpos As Integer
Const ToolbarName = "My Toolbar"
' Get the UIObject object for the toolbars.
If Visio.Application.CustomToolbars Is Nothing Then
If Visio.ActiveDocument.CustomToolbars Is Nothing Then
Set UI = Visio.Application.BuiltInToolbars(0)
Else
Set UI = Visio.ActiveDocument.CustomToolbars
End If
Else
Set UI = Visio.Application.CustomToolbars
End If
Set ToolbarSet = UI.ToolbarSets.ItemAtID(visUIObjSetDrawing)
' Delete toolbar if it exists already
TotalToolBars = ToolbarSet.Toolbars.Count
For i = 1 To TotalToolBars
Set Toolbar = ToolbarSet.Toolbars.Item(i - 1)
If Toolbar.Caption = ToolbarName Then
Toolbar.Visible = False
Toolbar.Delete
Exit For
End If
Next
' create toolbar
Set Toolbar = ToolbarSet.Toolbars.Add
Toolbar.Caption = ToolbarName
Dim IconPos As Long ' counter to determine where to put a button in the toolbar
IconPos = IconPos + 1
Dim IconFunction As String
IconFunction = """Macros.Module1.SubName"""
Set ToolbarItem = Toolbar.ToolbarItems.AddAt(IconPos)
With ToolbarItem
.AddOnName = "RunStencilMacro """ & IconFunction & """"
.Caption = "Button 1"
.CntrlType = Visio.visCtrlTypeBUTTON
.Enabled = True
.state = Visio.visButtonUp
.Style = Visio.visButtonIcon
.Visible = True
.IconFileName ("16x16IconFullFilePath.ico")
End With
' Now establish the position of this toolbar
With Toolbar
.Position = visBarTop 'Top overall docking area
.Left = 0 'Puts it x pixels from the left
.RowIndex = 13
.Protection = visBarNoCustomize
Toolbar.Enabled = True
.Visible = True
End With
Visio.Application.SetCustomToolbars UI
Visio.ActiveDocument.SetCustomToolbars UI
End Sub

Macro to wrap selected text with tags in Visual Studio

I realize that I may be being a bit lazy, but does anyone know of a Visual Studio macro, where I can select some text inside of the Visual Studio IDE, click a button, and have it wrap the selected text with tags? It would generate something like:
<strong>My Selected Text</strong>
I would even be up for creating a macro, just not sure where to exactly start!
The code to do so is rather simple:
Sub SurroundWithStrongTag()
DTE.ActiveDocument.Selection.Text = "<strong>" + DTE.ActiveDocument.Selection.Text + "</strong>"
End Sub
Now, if you don't know much about macros here's how to add it:
First you need open the macros IDE, click Tools->Macros->Macros IDE...
Next, we will add a module for your custom macros. Right click on "MyMacros" in the Project Explorer, click Add->Add Module..., type in an appropriate name then click "Add".
Now paste the function inside the module, making copies for any other tags you want
Save and close the macros IDE
To hook the macro up to a button:
Click Tools->Customize...
Click New..., type in an appropriate name, click OK. An empty toolbar should be visible (you may have to move the window to see it)
Click the Commands tab, and select "Macros" in categories
Find the macros created before and drag them over to the toolbar
Right click the buttons to change settings (such as displaying an icon instead of text)
I know this is an old topic, but maybe someone finds this useful.
I have the following set up:
Sub WrapInH1()
WrapInTag("h1")
End Sub
Sub WrapInP()
WrapInTag("p")
End Sub
Sub WrapInStrong()
WrapInTag("strong")
End Sub
Sub WrapInTag()
WrapInTag("")
End Sub
Sub WrapInTag(ByVal tagText As String)
EnableAutoComplete(False)
If tagText.Length = 0 Then
tagText = InputBox("Enter Tag")
End If
Dim text As String
text = DTE.ActiveDocument.Selection.Text
text = Regex.Replace(text, vbCrLf & "$", "") 'Remove the vbCrLf at the end of the line, for when you select the line by clicking in the margin, otherwise your closing tag ends up on it's own line at the end...
DTE.ActiveDocument.Selection.Text = "<" & tagText & ">" & text & "</" & tagText & ">" & vbCrLf
EnableAutoComplete(True)
End Sub
Private Sub EnableAutoComplete(ByVal enabled As Boolean)
Dim HTMLprops As Properties
Dim aProp As EnvDTE.Property
HTMLprops = DTE.Properties("Texteditor", "HTML Specific")
aProp = HTMLprops.Item("AutoInsertCloseTag")
aProp.Value = enabled
End Sub
Dim HTMLprops As Properties = DTE.Properties("Texteditor", "HTML Specific")
Dim aProp As EnvDTE.Property = HTMLprops.Item("AutoInsertCloseTag")
aProp.Value = False
Original answer
If you want an out of the box solution, Visual Studio 2015 comes with a new shortcut, Shift+Alt+W wraps the current selection with a div. This shortcut leaves the text "div" selected, making it seamlessly changeable to any desired tag. This coupled with the automatic end tag replacement makes for a quick solution.
Example
Shift+Alt+W > strong > Enter

Resources