distance between all typing of character in vb6.0 - vb6

draw a form1 in vb6 and draw textbox1 in form1 and press f5 run this program. when i type " abc1234 " in textbox1 typing start this " abc1234 " but i show type " a b c 1 2 3 4 " in textbox1.
Its mean only some distance between all typing character.
for example
input of html
using css
letter-spacing: 1px;
when i type in input some distance between all typing

If I understand you correctly, you want margin to be added between the characters in the Textbox.
This is not possible in standard control, unless you manually append and manage spaces to the text within the Textbox. Which will be a pain to manage (when using backspace/copy-paste/different culture/languages/etc).
Its better to look for a third-party control, or better alter your requirements.
In worst case - Highly not-recommended - develop your own VB6 ActiveX Control (some people call it UserControl, because of the way designer shows it).
Mind you, TextBox/Edit control is way more complex than custom designing other controls, since it contains text, which is extremely tricky to handle due to multiple locals/languages/windows themes/and what not.

Well if you must add spacing to a Textbox this is how you would do it manually:
Dim oldString as String
Dim newString as String
oldString = "babel"
for i = 1 to len(oldString)
newString = newString & Space(2) & Mid(oldString,i,1)
Next
msgbox newString
Like subdeveloper said this is not recommended but in case you must add spacing to your control this is how you would do it.

Related

Text kerning in Microsoft rich text box

This one has me awfully confused...
I am trying to display kerned RTF text in a Visual Studio Visual Basic RichTextBox control (having so far tried under VS2010 and VS2012). Simply, I create a Windows Form project, add two RichTextBox's (RichTextBox1 and RichTextBox2) to the form, no change to default properties, and include the following VB code:
Public Class Form1
Private Sub Initialise(sender As System.Object, e As System.EventArgs) Handles Me.Load
Dim txtRTF As String = "{\rtf1\ansi" & _
"{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}" & _
"\f0\pard" & _
"\expndtw-60 a" & _
"\expndtw200 b" & _
"\expndtw-20 c}"
RichTextBox1.Rtf = txtRTF
RichTextBox2.Paste() ' RichTextBox2 formats properly iff clipboard holds ANY valid rtf content
RichTextBox2.Rtf = txtRTF
End Sub
End Class
The txtRTF String contains, as best as I can tell, minimal valid RTF markup and text.
Here's the confusing bit: text displayed in RichTextBox1 is not kerned, despite \expndtw (expand twips) RTF markup, BUT text displayed in RichTextBox2 is properly kerned, if and only if the clipboard holds ANY valid RTF content (e.g., any text has first been copied into the clipboard from an MS Word document). Text displayed in RichTextBox2 is not properly kerned if clipboard contents is not RTF format.
Result of running if the clipboard does not contain RTF-formatted data (or if the RichTextBox2.Paste() code is removed or commented out):
Result of running if the clipboard holds any random RTF-formatted text:
Questions:
Why on earth should it matter that I have previously pasted RTF-format (and not non-RTF format) into the RichTextBox2 control before setting the RichTextBox2.Rtf field?
More importantly, how can I (in VB) programmatically display properly kerned text in a RichTextBox control without the absurdity of first pasting random RTF format text into it?
Well, that took a lot of work! Nevertheless, problem now solved.
It turns out that, although the RTF spec notes that \ltrch (left-to-right character run) is the default state, it seems that RichTextBox objects don't necessarily agree. Including a \ltrch (or even, oddly, a \rtlch) control sequence in the RTF markup stream completely solves the failure-to-kern problem. RTF text kerning via \expndtwN and \expndN now works perfectly well. No need for silly Paste() commands to pre-configure the RichTextBox control into its proper state!

Single Space Indent

Sometimes when i'm working in visual studio, I end up with a block of code that I need to indent a single space in order to make it align completely.
A normal sized indent would be done by selecting the text and pressing the tab key, however if I just want to move it along one space, selecting the text and pressing the space bar overwrites the code.
I know I could do this this by changing the tab spacing option so the indent size is 1, indenting the text and then changing it back but this seems a bit longwinded...
I've had no luck searching, so I've written a macro to do the above, but I thought i'd ask on here before i resigned to using it just in case the function/shortcut already existed...
Edit: Macro moved to answers
Here is said macro for anyone interested:
Sub SingleSpaceIndent()
Dim textEditor As Properties
textEditor = DTE.Properties("TextEditor", "AllLanguages")
textEditor.Item("IndentSize").Value = 1
DTE.ActiveDocument.Selection.Indent()
textEditor.Item("IndentSize").Value = 4
End Sub

Make a character appear only once on VB6

I'm creating a simple calculator on VB6.
Here's my code I'm working on:
textScreen.Text = textScreen.Text & "+"
Here's the result when I press some number buttons, followed by clicking on
the plus sign button several times:
75+++++++
I would like the plus sign to appear only once, even if I click on
its button many times:
92+
...and when I click on some number buttons again, followed by clicking
on the plus sign button, I would like the plus sign to show up again:
58+4+
This is somehow similar to the default Calculator on Windows 7.
Well, there are different approaches for this. But in general, I wouldn't just concatenate some string. This way you'll have to parse the string later on, instead of just solving the requested term. Instead try to create some stack with your operations/numbers on it; just look on the web for calculator examples.
Anyway, for this, you'll have to somehow store the last operation (e.g. did I input a digit or an operator?)
If you'd like to limit the calculator to simple operations without brackets etc. you can use a boolean value for this:
Dim lastOp As Boolean
Then, before adding the + (or any other operator):
If Not lastOp Then
textScreen.Text = textScreen.Text & "+"
lastOp = true
End If
When adding any digit (e.g.):
lastOp = false
textScreen.Text = textScreen.Text & "0"
(Don't count on 100% error free code, I think I haven't touched VB6 for like 8 years.)
You mighty just check if the last character in the text was "+" :
If Mid(textScreen.Text, Len(textScreen.Text), 1) <> "+" Then
textScreen.Text = textScreen.Text & "+"
End If

Does anyone know a visual studio keyboard short cut to swap around two sides of a statement?

Just wondering if anyone knows the keyboard shortcut to swap around two sides of a statement. For example:
I want to swap
firstNameTextbox.Text = myData.FirstName;
to
myData.FirstName = firstNameTextbox.Text;
Does anyone know the shortcut, if there is one? Obviously I would type them out, but there is a lot of statements I need to swap, and I think a shortcut like that would be useful!
Feel free to throw in any shortcuts you think are cool!
My contribution would be CTRL + E, D - this will format your code to Visual Studio standards! Pretty well known I'm guessing but I use it all the time! :)
UPDATE
Just to let everyone know, using a bit of snooping of the article that was posted, I managed to construct a regular expression, so here it is:
Find:
{.+\.Text = myData\..+};
And replace with:
\2 = \1;
Hopefully people can apply this to their own expressions they want to swap!
I think the following thread is a good place to begin with
Invert assignment direction in Visual Studio
Here's how I would go about doing that without a specific keyboard shortcut:
First, select the text you want to modify and replace
" = " with " = "
(the key here is to add a lot of spaces).
If you hold down Alt and use the mouse, you can select a "block" of code. Use this to select only the text on the right side of the equation (it's helpful to add extra white space here in your selection)
Use the same Alt + Left-Click combination to select the beginning of the left side (just select a blank area). You should be able to paste text into here.
If you added extra white space to the text you just added, just should be able to easily insert an = using the Alt + Click technique. Use the same trick to remove the equal sign that's dangling on the right side of your code block.
While this might not do exactly what you're looking for, I've found these tricks quite useful.
If you're using ReSharper, you can do this by pressing CtrlAltShift + ← or →
The feature is in Resharper. Select the code segment and click the content wizard, which is a pencil icon in the left corner reading View Actions List, then choose Reverse Assignment.
It is done.
swap-word is a VSCode extension which sounds like it would do what you want.
Quickly swap places two words or selections...
But I'm not sure if it is compatible with VS.
Since I was not happy with the answers where I need to enter complicated strings into the Visual Studio search/replace dialog, I wrote myself a little AutoHotkey script, that performs the swaps with only the need to press a keyboard shortcut. And this, no matter if you are in VS or in another IDE.
This hotkey (start it once simply from a textfile as script or compiled to exe) runs whenever Win+Ctrl-S is pressed
#^s Up::
clipboard := "" ; Empty the clipboard
Sendinput {Ctrl down}c{ctrl up}
Clipwait
Loop, Parse, clipboard, `n, `r ; iterates over seperates lines
{
array := StrSplit(RegExReplace(A_LoopField,";",""),"=") ; remove semicolon and split by '='
SendInput, % Trim(array[2]) . " = " . Trim(array[1]) . ";{Enter}"
}
return
Many more details are possible, e.g. also supporting code where lines end with a comma
...and I can put many more hotkeys and hotstrings into the same script, e.g. for my most mistyped words:
::esle::else ; this 1 line rewrites all my 'else' typos
I recommend using the find-replace option in Visual Studio. IMHO the REGEX string is not that complicated, and moreover, you don't need to understand the expression in order to use it.
The following regex string works for most programming languages:
([\w\.]+)\s*=\s*([\w\.]+)
For Visual Studio's you want to use $ argument in the replace text.
$2 = $1
Make sure to enable regex.
To do this in one shot, you can select a section of the document, and click the replace-all option.
Before:
comboBoxAddOriginalSrcTextToComment.SelectedIndex = Settings.Default.comboBoxAddOriginalSrcTextToComment;
comboBoxDefaultLanguageSet.SelectedIndex = Settings.Default.comboBoxDefaultLanguageSet;
comboBoxItemsPerTransaltionRequest.SelectedIndex = Settings.Default.comboBoxItemsPerTransaltionRequest;
comboBoxLogFileVerbosityLevel.SelectedIndex = Settings.Default.comboBoxLogFileVerbosityLevel;
comboBoxScreenVerbosityLevel.SelectedIndex = Settings.Default.comboBoxScreenVerbosityLevel;
After:
Settings.Default.comboBoxAddOriginalSrcTextToComment = comboBoxAddOriginalSrcTextToComment.SelectedIndex;
Settings.Default.comboBoxDefaultLanguageSet = comboBoxDefaultLanguageSet.SelectedIndex;
Settings.Default.comboBoxItemsPerTransaltionRequest = comboBoxItemsPerTransaltionRequest.SelectedIndex;
Settings.Default.comboBoxLogFileVerbosityLevel = comboBoxLogFileVerbosityLevel.SelectedIndex;
Settings.Default.comboBoxScreenVerbosityLevel = comboBoxScreenVerbosityLevel.SelectedIndex;
IMHO: It's better for a developer to learn to use the IDE (Integrated Development Environment), then to create new tools to do the same thing the IDE can do.

How to display the text file while clicking the button

How to display the file(*.txt) while clicking the command button
How to display the content of the file while clicking the button
Data's are stored in the text file, ex 1.txt
when am clicking the command buttion, 1.txt file will open and 1.txt data's should display
Add a textbox to a form, make it multiline=true, add a button to the form.
And in the buttons click handler add this:
Private Sub Button1_Click()
Dim iFile As Long
Dim strFilename As String
Dim strTheData as String
strFilename = "C:\1.txt"
iFile = FreeFile
Open strFilename For Input As #iFile
strTheData = StrConv(InputB(LOF(iFile), iFile), vbUnicode)
Close #iFile
text1.text=strThedata
End Sub
This will read the text in the file and add it to the textbox.
Edit: Changed the line that reading the content to be more robust as pointed out by MarkJ in this answer (Cred goes to to MarkJ to pointing out that.)
Stefan's answer contains a flaw: the code to read a text file into a string isn't very robust. It's a very common mistake - the same flawed code is on some excellent VB6 web sites. His code is
Open strFilename For Input As #iFile
strTheData = Input$(LOF(iFile), #iFile)
Close #iFile
Unfortunately this throws an error 62 "input past end of file" if the text file contains ASCII zero characters. Also it doesn't work in all countries (it throws an error for most strings in double byte character sets like Chinese or Japanese).
Perhaps those problems are a bit obscure: but there's better code to do this job in the VB6 manual (here), it's also three lines, and it never fails.
Open strFilename For Input As #iFile
strTheData = StrConv(InputB(LOF(iFile), iFile), vbUnicode)
Close #iFile
It looks more complicated: but actually the only difference is that the conversion from ANSI to Unicode is explicit rather than implicit. It runs just as fast, and it always works.
No offence intended, but it sounds like you need a beginners tutorial on VB6.
(I think this because you don't seem to be able to articulate exactly what you need help with, possibly because you don't know enough about what you're trying to do).
Googling for VB6 Tutorial will give lots of links, this one looks good
Hope this helps, and apologies if I'm wrong :)
To just open a file using the current default file handler try using the ShellExecute API function.
Here's an example.

Resources