Write text to log file Columns - vb.net

How do I write to the columns in a .log file?
I.e there are columns for "Log Text","Component","Date/Time"
How do I specify these when writing to a file?
I've got half of it working:
dim str As String ="<![LOG[" & message & "]LOG]!><time=""" & Now.ToLongTimeString & """" & " date=""" & Now.ToShortDateString & """ component=""" & component.ToString & """" & " type=""1""" & " Thread=""" & t & """" & ">"
File.AppendAllText(logfile, str & vbCrLf)
But the component, date / time and thread values arent displaying properly.
What am I missing ?
*edited
The file path is "C:\Programdata\server.log"
So some of the text is getting into it in the right place, just not all of it.
So the log text column will get populated with "message" and thread comes in with the number but the date/time and component are empty.
I'd attach a pic but i dont have enough rep :/
In a sentance, Im trying to replicate this:
http://www.jetico.com/web_help/bcwipe6_enterprise/img/log_viewer.jpg
but not all of my columns are displaying data.

Try dividing your data into columns using commas as suggested by #Blackwood, but use string.format as you seem to have lots of extra "" in there
Dim str As String = String.Format("![LOG[{0}]LOG]!,time={1}, <date= {2}, component= {3}, type=1, Thread={4}", Message, Now.ToLongTimeString, Now.ToLongDateString, component.ToString, t)
File.AppendAllText(logfile, Str() & vbCrLf)
I'm not sure what you are doing with the <> tags.

Solved.
This is to do with the format of the data I was trying to write.
Time has to be in the format
Now.ToLongTimeString & "." & Now.Millisecond & "-60"
and date has to be seperated with - instead of /
Dunno why - when viewed the time doesnt go to that length and the date is displayed with "/"
The viewer im using for the log was cmtrace.
This was the line that got it working was ..
<![LOG[" & message & "]LOG]!><time=""" & Now.ToLongTimeString & "." & Now.Millisecond & "-60" & """" & " date=""" & d & """ component=""" & component.ToString & """" & " type=""1" & """ Thread=""" & t &""">

Related

Trouble creating a comma-separated output string using variables

I am trying to create a string output where each of the variables are quoted and separated by a comma. This is the code I'm trying to use.
objOutputFile7.WriteLine(""& strCodeSetName & "'","'" & strCreateID & "'","'" & strSiteCode & "'","'" & strSiteName & "'","'" & strSiteName &"'",""false",,,,"false"")
I've been bouncing between 2 different errors. One that tells me a cannot use parentheses while calling a Sub. The other stating it's expecting a close-parentheses inside one of the variable names.
I've looked through online resources and could not find a close example. Could someone help me resolve my conundrum?
It's difficult to know exactly what output you expect/want, but maybe something like this?
objOutputFile7.WriteLine "'" & strCodeSetName & "','" & _
strCreateID & "','" & strSiteCode & "','" & _
strSiteName & "','" & strSiteName & "',false,,,,false"
One possibility is using the Join function. You have to create an array with all your variables...
Dim outLine as String
Dim myValues as Variant
myValues = Array(strCodeSetName, strCreateID, strSiteCode, _
strSiteName, strSiteName, "false,,,,false")
outLine = Join(myValues, ",")
objOutputFile7.WriteLine outLine

Excel VBA - insert formula in a set of rows with variable reference directly or replacing a string for example "\=" with "="

I have the goal to write a formula in a set of rows. Some references in the formula have to change each row.
I implemented the following script:
Dim i As Integer
Dim formcolM As String
Dim temprng As String
For i = 0 To 100
formcolM = "NUMBERVALUE(IF(Q" & i & "=""Bedarf kum."";A" & i & ";IF(Q" & i & "=""Ist"";OFFSET(A" & i & ";-1;0);IF(Q" & i & "=""Lz."";OFFSET(A" & i & ";-2;0);IF(Q" & i & "=""Ist+Lz.-Bedarf"";OFFSET(A" & i & ";-3;0);)))))"
Let temprng = "M" & i
Range(temprng).Select
ActiveCell.Value = "\=" & formcolM
next i
With this script I am writing a string each row in my excel table at column M.
I noticed that if the formula hasn't the symbol "\" , you can find an error .
In order to avoid the error I thought to leave the symbol "\" and to use a trick deleting it after (because I don't know how to solve with R1C1 formula. I read some answers on Stackoverflow, but unfortunately I did not understand )
The replacing script after the for cycle:
Columns("M:M").Replace What:="\=", Replacement:="=", LookAt:=xlPart
The strange thing is that the macro doesn't delete it.
Infact when the script finishes , it seems that nothing happened, without errors. But if I want substitute "\=" with another symbol, for example "*", the replacing script works.
I did not understand if the problem is :
the replace method did not recognized the symbol "=" to search
I cannot use the replace method because the symbol "=" disturbs in some way , I don't know in what.
OR, is there another simplest way to get this task done?
Someone could help me in order to fix? I should have the formula working in the column M , automatically with vba (not with another formula in the excel sheet) .
Thanks in advance for your time.
We can apply the formula directly. The issue is that vba is very US-EN Centric and all formula when using the .Formula needs to be in that format.
Also since your formula refers to values in a row 3 above the one in which it is put we need to start the loop at 4 not 0. There is no row 0
There are two ways, in US-En format with English functions and , as the deliminator using .Formula:
Dim i As Integer
For i = 4 To 100
Range("M" & i).Formula = "=NUMBERVALUE(IF(Q" & i & "=""Bedarf kum."",A" & i & ",IF(Q" & i & "=""Ist"",OFFSET(A" & i & ",-1,0),IF(Q" & i & "=""Lz."",OFFSET(A" & i & ",-2,0),IF(Q" & i & "=""Ist+Lz.-Bedarf"",OFFSET(A" & i & ",-3,0),)))))"
Next i
Or using .FormulaLocal and the formula as you would write it in your native tongue.
Dim i As Integer
For i = 4 To 100
Range("M" & i).FormulaLocal = "=NUMERO.VALORE(SE(Q" & i & "=""Bedarf kum."";A" & i & ";SE(Q" & i & "=""Ist"";SCARTO(A" & i & ";-1;0);SE(Q" & i & "=""Lz."";SCARTO(A" & i & ";-2;0);SE(Q" & i & "=""Ist+Lz.-Bedarf"";SCARTO(A" & i & ";-3;0);)))))"
Next i
By the time I got this worked out, Scott already had an answer. I just wanted to post your original code modified to work. I would suggest his method.
Sub TestScript()
Dim i As Integer
Dim formcolM As String
Dim temprng As String
For i = 4 To 100
formcolM = "NUMBERVALUE(IF(Q" & i & "=" & "Bedarf kum." & ";A" & i & ";IF(Q" & i & "=" & "Ist" & ";OFFSET(A" & i & ";-1;0);IF(Q" & i & "=" & "Lz." & ";OFFSET(A" & i & ";-2;0);IF(Q" & i & "=" & "Ist+Lz.-Bedarf" & ";OFFSET(A" & i & ";-3;0);)))))"
temprng = "M" & i
Sheets("Sheet1").Range(temprng).Select
ActiveCell.Value = " = " & formcolM
Next i
End Sub

IIF ISNOTHING Expression

I'm launching a sub-report to a separate window in reporting services by a JavaScript function as seen below,
=iif(Fields!PERIOD.Value <= Cint(right(Parameters!YEARPERIOD.Value, 2)),
"javascript:void(window.open('"
& Globals!ReportServerURL
& "?"
& Left(Globals!ReportFolder, InStr(Globals!ReportFolder, "/Standard Reports"))
& "Sub Reports/Trend Breakdown"
& "&ServerName="
& REPLACE(Parameters!ServerName.value,"\","\\")
& "&CATALOG="
& Parameters!CATALOG.Value
& "&NOMINAL="
& Fields!NOMINAL.Value
& "&COMPANYCODE="
& JOIN(Parameters!COMPANYCODE.Value, ",")
& "&YEARCODE="
& LEFT(Parameters!YEARPERIOD.Value, 7)
& "&LOCATION="
& Fields!LOCATION.Value
& "&KEYLISTGROUPING="
& Fields!KEYLISTGROUPING.Value
& "&ANALYSISCODE="
& Fields!ANALYSISCODE.Value
& "&BUDGET="
& Fields!BUDGET.Value
& "&PERIOD="
& Fields!PERIOD.Value
& "&ParentReport=3
&ADD_PERIODS="
& JOIN(Parameters!ADD_PERIODS.Value, ",")
& "','_blank','width=950,height=460,top=300'))", "")
Now i'm trying to change the & Globals!ReportServerURL to the following
& IIF(IsNothing(Parameters!GetExternal.Value), "Globals!ReportServerUrl", Parameters!GetExternal.Value)
Essentially replace the ReportServerURL in the sub-report link if there is a value in the GetExternal parameter.
But it isn't updating the report server url in the sub-report correctly, but instead appending the value from the parameter to the following part of the sub-report link, see the red box,
Question i have is how can i make it append the parameter value to the following part of the link? See the red highlighted section,

how to use variable containing strings in formula vba

I ask the user input for a string and then need to incorporate this into a formula. I searched on other questions but didn’t get the desired output.
Sname = InputBox("Enter name")
Cells(2, 32).FormulaR1C1 = _
=CONCATENATE(J2,""-"",K2,""-"",L2,""-"" "" & Sname & "" -"",T2,U2,V2,W2,X2,Y2,""-"",AB2,""-"",AC2)
suppose i enter AAA
i want the formula on cell(2,32) to be
=CONCATENATE(J2,"-",K2,"-",L2,"-" & "AAA" & "-",T2,U2,V2,W2,X2,Y2,"-",AB2,"-",AC2)
Try this:
Cells(2,32).Formula = _
"=CONCATENATE(J2,""-"",K2,""-"",L2,""-"" & """ & Sname & """ & ""-"",T2,U2,V2,W2,X2,Y2,""-"",AB2,""-"",AC2)"
There was a slight mixup with your quotation marks around the variable.
This one works for me.
swap " for ' Tip: you can use CTRL+U
=CONCATENATE(J2,'-',K2,'-',L2,'-' & 'AAA' & '-',T2,U2,V2,W2,X2,Y2,'-',AB2,'-',AC2)
Add a replace function
Replace("=CONCATENATE(J2,'-',K2,'-',L2,'-' & 'AAA' & '-',T2,U2,V2,W2,X2,Y2,'-',AB2,'-',AC2)","'", Chr(34))
Chr(34) equal to caracter "

CSV in visual Basic

I am trying to seperate the text box list I have using csv. I am saving it to excel and the titles that I have go into their individual cell, but the text boxes go into one. I want them to be in their seperate cell also.
Also, how can I add new information without overwriting the previous info saved?
Thanks
Dim csvFile As String = My.Application.Info.DirectoryPath & "\HoseData.csv"
Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, False)
outFile.WriteLine("job number, sales order number, date")
outFile.WriteLine(TextBox1.Tex & TextBox2.Text & DateTimePicker1.Text)
outFile.Close()
Console.WriteLine(My.Computer.FileSystem.ReadAllText(csvFile))
You need to add commas in your output:
outFile.WriteLine(TextBox1.Text & "," & TextBox2.Text & "," & DateTimePicker1.Text)
Per the additional requirement of quotes around the DateTimePicker data that was fleshed out in the comments below:
outFile.WriteLine(TextBox1.Text & "," & TextBox2.Text & "," & """" & DateTimePicker1.Text & """")
To append instead of overwrite, as Plutonix mentioned above, use
OpenTextFileWriter(csvFile, True)