Visual Basic 6 Command included on String Table - vb6

Here is the situation, I have this string table, in a .res file and I have some strings loaded into one of the forms, say Form1. On a form on I want to popup a message box with a message loaded from the string table using LoadResString(1234).
Is it possible that when Resource ID 1234 contains "This is testing vbNewline This is a new line!." that string will be loaded using the said function onto the message box (popup box)?
I've tested it: It will also print out the "vbNewline" command and NOT parse it. Is there any other way to parse the said string making this kind of message ?
This is testing
This is new line!.
I wanted that kind of message to appear.

You are trying to put a VB constant in a String expression so it is treating it like text, you can try using the Replace Function ( I realize this is a .Net link but the signature is the same as the VB6 method) to remove your string and substitute the correct value something like this should work:
MsgBox (Replace(LoadResString(1234), "vbNewLine", vbNewLine))
or create a function like this:
Public Function ParseNewLine(value As String) As String
ParseNewLine = Replace(value, "vbNewLine", vbNewLine)
End Function
and call it like this:
MsgBox (ParseNewLine(LoadResString(1234)))

Why don't you embed the newline sequence into the RES file. If you are using the Resource Add-In, you can press Ctrl+Enter to insert these characters.
In visual Studio's resource editor and a raw resource script, you can use \n.

Related

Scripting Word from vbs

I'm trying to get Word to fill in cells in a table. The script works when run as a macro from within Word, but fails when saved as a .vbs file and double-clicked, or run with wscript. This is a part of it.
set obj = GetObject(,"Word.Application)
With obj
With .Selection
MsgBox .text
If (.Information(wdWithInTable) = True) Then
.Collapse Direction:=wdCollapseStart
tCols = .Tables(1).Columns.Count
tRow = .Information(wdStartOfRangeRowNumber)
tCol = .Information(wdStartOfRangeColumnNumber)
For I = 2 To 5
.Tables(1).Cell(tRow, I).Range.Text = "fred" & Str(I)
Next
` now make new row
For I = 1 To tCols - tCol + 1
.MoveRight unit:=wdCell
Next
End If
End With
End With
I have three problems. First, it won't compile unless I comment out the .Collapse and .MoveRight lines. Second, although the MsgBox .text displays the selected text, I get "out of range" errors if I try to access any .Information property.
I'm sure I'm missing something very simple: I usually write software for Macs, and I'd do this using AppleScript. This is my first attempt at getting anything done under Windows.
VBScript and VBA are different languages.
They are a bit similar, but not very. Moreover, VBScript is not like AppleScript; it doesn't let you easily interface with running programs.
The interfaces you'll get from VBScript can behave subtly differently in VBA and VBScript. However, I think you've got two problems here:
:= is invalid syntax in VBScript; you'll need to find an alternative way of calling the function. Try just using positional arguments.
You've no guarantee that this will open the expected file; there could be another instance of Word that it's interacting with instead.
Since your code is not running within the Word environment it would require a reference to the Word object library in order to use enumeration constants (those things that start with wd).
VBScript, however, cannot work with references, which means the only possibility is to use the long value equivalents of the enumerations. You'll find these in the Word Language References. Simplest to use is probably the Object Browser in Word's VBA Editor. (In Word: Alt+F11 to open the VBA Editor; F2 to start the Object Browser; type in the term in the "Search" box, click on the term, then look in the bottom bar.)
The code in the question uses, for example:
wdWithInTable
wdCollapseStart
wdStartOfRangeRowNumber
wdStartOfRangeColumnNumber
wdCell
The reason you get various kinds of errors depends on where these are used.
Also, VBScript can't used named parameters such as Unit:=. Any parameters must be passed in comma-delimited format, if there's more than one, in the order specified by the method or property. If there are optional parameters you don't want to use these should be left "blank":
MethodName parameter, parameter, , , parameter

How to write an expression to display 2 fields in a string in Visual Studio

I am trying to take two fields and display them in a string in my SSReport. How would I properly write the expression for this type of scenario.
Fields!Title1.Value
Fields!Title2.Value
Expression:
= Fields!Title1.Value is stored in the Fields!Title2.Value room.
Try this in a textbox:
=CStr(Fields!Title1.Value) & CStr(Fields!Title2.Value)

how to format the specified string as bold and set size in testcomplete using VB scripting language inj testcomplete

I am trying to set the format for a particular string as bold and font size and colorindex.i am using VB script in testcomplete tool.can you please suggest me which method is used for that
sub sample
mystring="welcome to testcomplete"
aqstring.format(mystring)=Bold
mystring.Font.ColorIndex=10
mystring.Font.size=14
end sub
here i am getting vb script run time error..please help me which method i have to use..give some examples
Well for it to add parameters on top of the string, the string needs to be attached to an object, for example, a log parameter below. A log parameter can support font styles because it is an object that does have more properties than text and length(like strings). In this case, a simple string cannot support font styles.
Sub EventControl1_OnUnexpectedWindow(Sender, Window, LogParams)
LogParams.MessageText = "An unexpected window has appeared."
' Specifies the string that will be posted to the Additional Info panel
LogParams.FontStyle.Bold = True
LogParams.FontColor = clSilver
LogParams.Color = clFuchsia
End Sub
Here is the complete directory on string manipulation -> Click Here
You'll notice that there are no articles on string formatting and colors, that's because a string is a scripting tool, and not an object that can support formatting.

Visual Basic - Writing / Overwriting into a text line adds a new line

Hello everyone I made a simple program that takes my external IP and places in a my websites public camera. And I got a problem - The program is making a txt file with the ip inside it and uploads it to the server.When the program is overwriting/editing/creating the file its adding an empty new line which messes up my PHP code...
This is the code used for both overwriting/editing and creating the file
Dim strFile As String = "c:/IPtoUse.txt"
Dim fileExists As Boolean = File.Exists(strFile)
Using sw As New StreamWriter(File.Open(strFile, FileMode.OpenOrCreate))
sw.WriteLine( _
IIf(fileExists, GetIP, GetIP))
End Using
(the GetIP function is getting my ip from my server)
This ends up with another empty line. How can I fix it?
Thanks!
Going on the information from the question and comments, it seems that your file will end up with an additional linefeed at the end in both cases (ie. both for new and modified files).
The reason for this is that you're using the WriteLine method, which will append a newline at the end of the text it writes, even if that text already ends with a newline.
Simply change the code to use the Write method instead of the WriteLine method and you should end up with a file that contains only the text passed to the method.

VS2010 save array/collection data to a file while debugging

Is there some way to save array/list/collection data to a file while debugging in VS2010?
For example, in this code:
var addressGraphs = from a in context.Addresses
where a.CountryRegion == "Canada"
select new { a, a.Contact };
foreach(var ag in addressGraphs) {
Console.WriteLine("LastName: {0}, Addresses: {1}", ag.Contact.LastName.Trim(),
ag.Contact.Addresses.Count());
foreach(var Address in ag.Contact.Addresses) {
Console.WriteLine("...{0} {1}", Address.Street1, Address.City);
}
}
I'd like to set a breakpoint on the first 'foreach' line and then save the data in 'addressGraph' to a file.
where 'a' contains fields such as:
int addressID
string Street1
string City
<Ect.>
and 'Contact' contains fields such as:
string FirstName
string LastName
int contactID
<Ect.>
I'd like the file to contain the values of each of the fields for each item in the collection.
I don't see an obvious way to do this. Is it possible?
When your breakpoint is hit, open up the Immediate window and use Tools.LogCommandWindowOutput to dump the output to a file:
>Tools.LogCommandWindowOutput c:\temp\temp.log
?addressGraphs
>Tools.LogCommandWindowOutput /off
Note: You can use Log which is an alias for Tools.LogCommandWindowOutput
Update:
The > character is important. Also, the log alias is case sensitive.
See screenshot:
I also encoutered such a question, but in VS2013. I have to save a content of array while debugging.
For example, I need to save a content of double array named "trimmedInput". I do so:
Open QuickWatch Window from Debug menu (Ctrl+D, Q).
Put your variable in Expression and push Recalculate Button
You'll see all the values. Now you could select them all (Ctrl+A) and copy (Ctrl+C).
Paste (Ctrl+V) them in your favorite editor. Notepad, for example. And use them.
That's the simples way that I know. Without additional efforts. Hope that my description helps you!
P.S. Sorry for non English interface on screenshots. All necessary information are written in the text.
Something similar is possible with this method:
I built an extension method that I use in all of my projects that is a general and more powerful ToString() method that shows the content of any object.
I included the source code in this link:
https://rapidshare.com/files/1791655092/FormatExtensions.cs
UPDATE:
You just have to put FormatExtensions.cs in your project and change the Namespace of FormatExtensions to coincide to the base Namespace of your project. So when you are in your breakpoint you can type in your watch window:
myCustomCollection.ToStringExtended()
And copy the output wherever you want
On Visual studio Gallery search for: Object Exporter Extension.
be aware: as far as I worked with, it has a bug that block you from exporting object once in a while.
You can also call methods in the Immediate Window, and so I think your best bet would be to use an ObjectDumper object, like the one in the LINQ samples or this one, and then write something like this in the Immediate Window:
File.WriteAllText("myFileName.txt", ObjectDumper.Dump(addressGraph));
Depending on which ObjectDumper you decide to use, you may be able to customize it to suit your needs, and to be able to tell it how many levels deep you want it to dig into your object when it's dumping it.
Here's a solution that takes care of collections. It's a VS visualizer that will display the collection values in a grid while debugging as well as save to the clipboard and csv, xml and text files. I'm using it in VS2010 Ultimate. While I haven't tested it extensively, I have tried it on List and Dictionary.
http://tinyurl.com/87sf6l7
It handles the following collections:
•System.Collections classes
◦System.Collections.ArrayList
◦System.Collections.BitArray
◦System.Collections.HashTable
◦System.Collections.Queue
◦System.Collections.SortedList
◦System.Collections.Stack
◦All classes derived from System.Collections.CollectionBase
•System.Collections.Specialized classes
◦System.Collections.Specialized.HybridDictionary
◦System.Collections.Specialized.ListDictionary
◦System.Collections.Specialized.NameValueCollection
◦System.Collections.Specialized.OrderedDictionary
◦System.Collections.Specialized.StringCollection
◦System.Collections.Specialized.StringDictionary
◦All classes derived from System.Collections.Specialized.NameObjectCollectionBase
•System.Collections.Generic classes
◦System.Collections.Generic.Dictionary
◦System.Collections.Generic.List
◦System.Collections.Generic.LinkedList
◦System.Collections.Generic.Queue
◦System.Collections.Generic.SortedDictionary
◦System.Collections.Generic.SortedList
◦System.Collections.Generic.Stack
•IIS classes, as used by
◦System.Web.HttpRequest.Cookies
◦System.Web.HttpRequest.Files
◦System.Web.HttpRequest.Form
◦System.Web.HttpRequest.Headers
◦System.Web.HttpRequest.Params
◦System.Web.HttpRequest.QueryString
◦System.Web.HttpRequest.ServerVariables
◦System.Web.HttpResponse.Cookies
As well as a couple of VB6-compatible collections
In "Immediate Window" print following to get the binary dump:
byte[] myArray = { 02,01,81,00,05,F6,05,02,01,01,00,BA };
myArray
.Select(b => string.Format("{0:X2}", b))
.Aggregate((s1, s2) => s1 + s2)
This will print something like:
0201810005F60502010100BA
Change the '.Aggregate(...)' call to add blanks between bytes, or what ever you like.

Resources