vb6 printer.print does not work in vb.net 201 - vb.net

Receive this error in build
Operator '&' is not defined for types 'String' and 'Microsoft.VisualBasic.TabInfo'
This is the line, what do I have to do to make this valid (which does work in vb6)
Printer.Print("ATICTS PROBLEM REPORT: " _
& txtCallId.Text & FileSystem.TAB(70) & "Hours to date:" _
& FileSystem.TAB(90) & txtHours.Text)

I would suggest that you break that up...
Printer.Print("ATICTS PROBLEM REPORT: ")
Printer.Print(txtCallId.Text)
Printer.Print(FileSystem.TAB(70))
Printer.Print("Hours to date:")
Printer.Print(FileSystem.TAB(90))
Printer.Print(txtHours.Text)
As understand it, FileSystem.Tab wasn't a simple tab character or number of spaces. I believe the above has the best chance of producing the same results.

Related

Access VBA error "Too few parameters. Expected 1"

I'm trying to find out why this is wrong, while in the queries generator it works properly.
SELECT Count(Audi.Id) AS CuentaDeId FROM Audi
WHERE (((Len." & filtro & ") Between #" & Format(Me!fechamin, "mm/dd/yyyy") & "# And #" & Format(Me!fechamax, "mm/dd/yyyy") & "#))
With some dates slightly different It works, but I think that when It does not find any value in this Table, the error appears.
No idea if it's a problem of the Query design, or if there is another way to define it, or not. Any clue, anyone?
Thanks in advance!
Len is a function name in SQL. That is why Access asked for the parameter. Besides, as Parfait said, Len is used in your query as an alias but not referring to any other table/query.

Comment out inline if statement in VB?

I am having problems trying to comment out an inline if statement in VB. Is this even possible? This syntax does not seem to be recognized in Visual Studio.
'IIf(BusinessFactor <> 1, " x Business Factor " & BusinessFactor& " = $" & brPremium & " (rounded)", "") & _
Thanks!
Your inline If-statement has a line continuation character (which is the underscore _) after it, which means that the whole statement continues on the next line.
You would need to put that continuation char before the comment, but as that is not possible (due to that the continuation character must be the last on that line) your only option is to (re)move the entire If.
In cases where you don't have a continuation character, commenting it out will work just fine.

VBA vbNewLine but with no extra space

I'm adding a Title to a chart but I keep getting an extra space (white space) between the two strings when I use vbNewLine.
myChart.ChartTitle.Text = "Distance to Default for" & vbNewLine & compName
note compName is another string I previously define.
Most probably it's a text format issue. Try: vbCrLf, vbCr, vbLf or (digged up the doc) Environment.NewLine. One of the four should be OK.
"Cr" is "carriage return" while "Lf" is "Line Feed" (these terms come from old typewriter times). Some OS/text format/system/whatever uses both "driver characters", some use just one of these - the white space you saw was an unnecessary "cr" or "lf" if that makes sense
Try vbCrLf:
myChart.ChartTitle.Text = "Distance to Default for" & vbCrLf & compName
EDIT: Try vbCr since vbCrLf looks to be identical to vbNewline
myChart.ChartTitle.Text = "Distance to Default for" & vbCr & compName
helpful post. I have the same issue. "text" & vbnewline & "text" is two carriage returns instead of one...
vbVerticalTab worked well for me.
I don't understand what end result you're aiming for, but using vbNewLine will insert a carriage return.
If you're just trying to insert a space between the text and the value then one of the following would work:
myChart.ChartTitle.Text = "Distance to Default for " & compName
myChart.ChartTitle.Text = "Distance to Default for" & Chr(32) & compName
So here's my solution. Use chr(10) instead of vbNewLine and then do this:
compName = Replace(compName, vbCrLf, Chr(10))
It worked for me. Don't know if it'll work for everyone. Cheers.
You can also use vbVerticalTab or Chr(11). This is the same as hitting shift + enter if you were typing a Word document.
Interestingly, in the Official documentation, VBA Miscellaneous constants, it says this in the description:
Not useful in Microsoft Windows or on the Macintosh
Of which I disagree. The documentation says the same thing about vbFormFeed / Chr(12), but you can use that to easily insert page breaks.

combine strings containing NULL

I am attempting to use the confluence REST API to attach files to a wiki page. I generate assorted graphs in excel using VBA and save them as images (currently as png/jpeg).
I then use the example here to upload a file to the wiki as an attachment. This method works well for text files, but when I attempt to use images I run into some issues. Specifically as I understand it the code:
sPostData = "--" & STR_BOUNDARY & vbCrLf & _
"Content-Disposition: form-data; name=""uploadfile""; filename=""" & Mid$(sFileName, InStrRev(sFileName, "\") + 1) & """" & vbCrLf & _
"Content-Type: application/octet-stream" & vbCrLf & vbCrLf & _
sPostData & vbCrLf & _
"--" & STR_BOUNDARY & "--"
attempts to add string boundaries to the binary representation of the file by concatenating string. My issue is that the representation for the png contains NUL
‰PNG
SUB
NULNULNUL
IHDRNULNULEOT+NULNULSTXSYNBSETXNULNULSOH>&Ǽ ...etc...
which promptly terminates the string, and so you lose the rest of the file and the final string boundary. I believe this occurs with all string functionality in excel.
My question is how should I go about attaching the string boundaries to my file so as to avoid this issue?
Thanks in advance :)
As Alex K. pointed out I have been working under an incorrect assumption. The truncation is present in my analysis of the issue and not the actual string.
The problem was actually due to a mistake on my part - from the webiste:
Another caveat is the pvToByteArray function. It turns out send
method can not handle “byref” byte arrays, so for instance passing
baBuffer will fail, as VB6 sets up VT_BYREF bit of the type of the
variant parameter.
It was my implementation of this part of the code that was incorrect - this caused the failure and the error message
500: Stream ended unexpectedly
After correcting this the issue appears resolved.
Thanks again Alex.

Converting characters to ASCII code

Need help with reading special characters within my VB code. ASCII code Char(34) = " works fine but Char(60) = < and Char(62) = > are not being read.
My Code
node.FirstChild.InnerText = Chr(60) & "httpRuntime executionTimeout=" & Chr(34) & "999999" & Chr(34) & " maxRequestLength=" & Chr(34) & "2097151" & Chr(34) & "/" & Chr(62)
Without ASCII Code
'node.FirstChild.InnerText = "<httpRuntime executionTimeout="999999" maxRequestLength="2097151"/>"
Are you trying to modify a Config file? Try:-
node.FirstChild.InnerXml = "<httpRuntime executionTimeout=""999999"" maxRequestLength=""2097151"" />"
Note all that Chr marlarky is unnecessary, were you trying to avoid < and > being encoded as XML entities?
Maybe this doesn't answer your question, but you could use two double quotes to escape the quotes character in VB.NET:
node.FirstChild.InnerText = _
"<httpRuntime executionTimeout=""999999"" maxRequestLength=""2097151"" />"
I'm just guessing: you could use the String.Format method for your purposes:
node.FirstChild.InnerText = _
String.Format( _
"<httpRuntime executionTimeout=""{0}"" maxRequestLength=""{1}"" />", _
timeoutValue.ToString(), reqLenValue.ToString())
You'll need to give more information about how you're "seeing" the results. In my experience, problems with this are as likely to be about viewing strings in the debugger as getting the right strings in the first place.
I don't really see why you need to use Chr(60) etc at all, other than for the quotes. What happens when you just use < and > in your code?
I strongly suggest you dump the string out to the console rather than using the debugger - the debugger tries to show you how you could represent the string in code, rather than showing you the contents verbatim.
Of course, if this is XML then I'd expect serializing the XML out again to end up escaping the < and > - again, more information about what you're trying to do would be helpful. The absolute ideal (IMO) would be a short but complete program demonstrating the problem - a small console app which does one thing, and a description of what you want it to do instead.