How to generate a list in an Access Report? - vba
I'm trying to generate a report in Microsoft Access which should make a list based on the content stored in a field called Exams in a Table named Checkup.
So far I have a report with a calculated field and a textbox with record source Exams. The calculated field uses Switch function to generate the list; here's the code:
=Switch([Examenes]="BHC","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "Gb:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:",[Examenes]="BHC, VDRL","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "Gb:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:" & Chr(13) & Chr(10) & "VDRL:",[Examenes]="BHC, EGO, VDRL","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "GB:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:" & Chr(13) & Chr(10) & "VDRL:" & Chr(13) & Chr(10) & "EGO" & Chr(13) & Chr(10) & "Color:" & Chr(13) & Chr(10) & "Densidad:" & Chr(13) & Chr(10) & "Ph:" & Chr(13) & Chr(10) & "SO:" & Chr(13) & Chr(10) & "Proteinas:" & Chr(13) & Chr(10) & "CE:" & Chr(13) & Chr(10) & "LL:" & Chr(13) & Chr(10) & "FM:" & Chr(13) & Chr(10) & "Nitrito:" & Chr(13) & Chr(10) & "Cristales:",[Examenes]="BHC, EGH, EGO, VDRL","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "Gb:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:" & Chr(13) & Chr(10) & "VDRL:" & Chr(13) & Chr(10) & "EGO" & Chr(13) & Chr(10) & "Color:" & Chr(13) & Chr(10) & "Densidad:" & Chr(13) & Chr(10) & "Ph:" & Chr(13) & Chr(10) & "SO:" & Chr(13) & Chr(10) & "Proteinas:" & Chr(13) & Chr(10) & "CE:" & Chr(13) & Chr(10) & "LL:" & Chr(13) & Chr(10) & "FM:" & Chr(13) & Chr(10) & "Nitrito:" & Chr(13) & Chr(10) & "Cristales:" & Chr(13) & Chr(10) & "EGH" & Chr(13) & Chr(10) & "Protozoarios:" & Chr(13) & Chr(10) & "Metazoarios:")
The code works well, however, I need to add more values to the Switch function but I get error message "The text is too long to be edited". Since this field is calculated I can't just go to the table and add more characters or make it into a memo type field (or I least I don't know how).
Is there a workaround to this issue? I've also tried putting the code to onLoad (or OnOpen) event in the report, but haven't gotten it to work. Access gives me Compile error: Expected: list separator or )
Here's the code:
Private Sub Report_Open(Cancel As Integer)
Switch([Examenes]="BHC","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "Gb:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:",[Examenes]="BHC, VDRL","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "Gb:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:" & Chr(13) & Chr(10) & "VDRL:",[Examenes]="BHC, EGO, VDRL","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "GB:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:" & Chr(13) & Chr(10) & "VDRL:" & Chr(13) & Chr(10) & "EGO" & Chr(13) & Chr(10) & "Color:" & Chr(13) & Chr(10) & "Densidad:" & Chr(13) & Chr(10) & "Ph:" & Chr(13) & Chr(10) & "SO:" & Chr(13) & Chr(10) & "Proteinas:" & Chr(13) & Chr(10) & "CE
:" & Chr(13) & Chr(10) & "LL:" & Chr(13) & Chr(10) & "FM:" & Chr(13) & Chr(10) & "Nitrito:" & Chr(13) & Chr(10) & "Cristales:",[Examenes]="BHC, EGH, EGO, VDRL","BHC" & Chr(13) & Chr(10) & "Hto:" & Chr(13) & Chr(10) & "Gb:" & Chr(13) & Chr(10) & "E:" & Chr(13) & Chr(10) & "S:" & Chr(13) & Chr(10) & "L:" & Chr(13) & Chr(10) & "M:" & Chr(13) & Chr(10) & "St:" & Chr(13) & Chr(10) & "B:" & Chr(13) & Chr(10) & "VDRL:" & Chr(13) & Chr(10) & "EGO" & Chr(13) & Chr(10) & "Color:" & Chr(13) & Chr(10) & "Densidad:" & Chr(13) & Chr(10) & "Ph:" & Chr(13) & Chr(10) & "SO:" & Chr(13) & Chr(10) & "Proteinas:" & Chr(13) & Chr(10) & "CE:" & Chr(13) & Chr(10) & "LL:" & Chr(13) & Chr(10) & "FM:" & Chr(13) & Chr(10) & "Nitrito:" & Chr(13) & Chr(10) & "Cristales:" & Chr(13) & Chr(10) & "EGH" & Chr(13) & Chr(10) & "Protozoarios:" & Chr(13) & Chr(10) & "Metazoarios:")
End Sub
Any help is greatly appreciated!
Try using a simple Select ... Case construct:
Private Sub Report_Open(Cancel As Integer)
Const BHC As String = "BHC" & vbCrLf & "Hto:" & vbCrLf & "Gb:" & vbCrLf & "E:" & vbCrLf & "S:" & vbCrLf & "L:" & vbCrLf & "M:" & vbCrLf & "St:" & vbCrLf & "B:"
Const VDRL As String = vbCrLf & "VDRL:"
Const EGO As String = vbCrLf & "EGO" & vbCrLf & "Color:" & vbCrLf & "Densidad:" & vbCrLf & "Ph:" & vbCrLf & "SO:" & vbCrLf & "Proteinas:" & vbCrLf & "CE:" & vbCrLf & "LL:" & vbCrLf & "FM:" & vbCrLf & "Nitrito:" & vbCrLf & "Cristales:"
Const EGH As String = vbCrLf & "EGH" & vbCrLf & "Protozoarios:" & vbCrLf & "Metazoarios:"
Dim Value As string
Select Case Me!Examenes.Value
Case "BHC"
Value = BHC
Case "BHC, VDRL"
Value = BHC & VDRL
Case "BHC, EGO, VDRL"
Value = BHC & VDRL & EGO
Case "BHC, EGH, EGO, VDRL"
Value = BHC & VDRL & EGO & EGH
End Select
' Display result.
Me!YourUnboundTextbox.Value = Value
End Sub
Related
SVG to display on button click event but how?
I have a textbox with some SVG code written in it and I would like to display it as my actual html page in a WebBrowser once the button click event is triggerd but I can see how to do that. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click TextBox1.Text = "<!DOCTYPE html><html><body><svg height=" & Chr(34) & "5000" & Chr(34) & " width=" & Chr(34) & "5000" & Chr(34) & "><g style=" & Chr(34) & "fill:none;stroke:rgb(255,0,0);stroke-width:0.1" & Chr(34) & " stroke-dasharray=" & Chr(34) & "40,5,10,5" & Chr(34) & "><line x1=" & Chr(34) & "0" & Chr(34) & " y1=" & Chr(34) & "0" & Chr(34) & " x2=" & Chr(34) & "200" & Chr(34) & " y2=" & Chr(34) & "150" & Chr(34) & "/><line x1=" & Chr(34) & "200" & Chr(34) & " y1=" & Chr(34) & "150" & Chr(34) & " x2=" & Chr(34) & "400" & Chr(34) & " y2=" & Chr(34) & "0" & Chr(34) & "/><polyline points=" & Chr(34) & "0,0 50,50 0,100 50,100 130,150 210,190" & Chr(34) & "/></g></svg></body></html>" WebBrowser1.Document.Write(TextBox1.Text) End Sub
If Then to un-protect and protect document
I have a userform that unprotects a document to let info be entered then protects the document. All of my subs work aside one. Ranges with if/thens don't work but basic if then works. Example of sub that works: Private Sub ComboBox5_Change() ActiveDocument.Unprotect "password" Dim ComboBox5 As Range Set ComboBox5 = ActiveDocument.Bookmarks("bmragpd").Range ComboBox5.Text = Me.ComboBox5.Value If Me.ComboBox5.Value = "No" Then ComboBox5.Text = "205.55a" End If If Me.ComboBox5.Value = "Yes" Then ComboBox5.Text = "" End If ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True, Password:="password" End Sub This sub will say the document is already unprotected. I tried removing the unprotect on combobox6: Private Sub ComboBox6_Change() ActiveDocument.Unprotect "password" Dim rngComboBox6 As Range Dim sssaText As String Dim iiia As Integer Set rngComboBox6 = ActiveDocument.Bookmarks("bmfcs").Range sssaText = ComboBox6.Value If Me.ComboBox6.Value = "Yes" Then For iiia = 1 To 1 sssaText = sssaText & Chr(13) & "200" _ & Chr(13) & "200.1" _ & Chr(13) & "" _ & Chr(13) & "OEBS" _ & Chr(13) & "" _ & Chr(13) & "21c" _ & Chr(13) & "" _ & Chr(13) & "22c" _ & Chr(13) & "Yes" _ & Chr(13) & "" _ & Chr(13) & "Yes" _ & Chr(13) & "Two" _ & Chr(13) & "" _ & Chr(13) & "ES2a.1" _ & Chr(13) & "" _ & Chr(13) & "222" _ & Chr(13) & "" _ & Chr(13) & "222a" _ & Chr(13) & "222b" _ & Chr(13) & "" _ & Chr(13) & "3.a.1" _ & Chr(13) & "" _ & Chr(13) & "NA" _ & Chr(13) & "" _ & Chr(13) & "I. TuuVa" Next iiia sssaText = sssaText & Chr(13) & "717217" _ & Chr(13) & "" _ & Chr(13) & "1212" _ & Chr(13) & "" _ & Chr(13) & "D.1" _ & Chr(13) & "F2B-4" End If rngComboBox6.Text = sssaText ActiveDocument.Bookmarks.Add "bmfcs", rngComboBox6 If Me.ComboBox6.Value = "No" Then ComboBox6.Text = "" End If ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True, Password:="password" End Sub
The first End If is in the wrong place. You are adding text to the document regardless of the value of the combo box. It is not good practice to use a control’s change event to commit changes to a document. Apart from anything else it doesn’t allow the user to cancel without making changes. Instead use an OK/Apply/Finish button. Then you only need to unprotect/reprotect the document once.
How to get the value without encoding in vb.net watch?
In vb.net in debugging you can watch a variable and right click. There are options between copy and copy value. There is little differences. I basically got this "[" & vbCrLf & " {" & vbCrLf & " ""id"": 22812485751," & vbCrLf & " ""currencyPair"": ""ORME/BTC""," & vbCrLf & " ""goodUntilTime"": 0," & vbCrLf & " ""type"": ""LIMIT_SELL""," & vbCrLf & " ""orderStatus"": ""EXECUTED""," & vbCrLf & " ""issueTime"": 1539721209920," & vbCrLf & " ""price"": 2.726E-05," & vbCrLf & " ""quantity"": 1733.83246147," & vbCrLf & " ""remainingQuantity"": 0.0," & vbCrLf & " ""commissionByTrade"": 8.508E-05," & vbCrLf & " ""bonusByTrade"": 0," & vbCrLf & " ""bonusRate"": 0," & vbCrLf & " ""commissionRate"": 0.0018," & vbCrLf & " ""lastModificationTime"": 1539727280096" & vbCrLf & " }," & vbCrLf & " {" & vbCrLf & " ""id"": 19661583751," & vbCrLf & " ""currencyPair"": ""ORME/ETH""," & vbCrLf & " ""goodUntilTime"": 0," & vbCrLf & " ""type"": ""LIMIT_BUY""," & vbCrLf & " ""orderStatus"": ""EXECUTED""," & vbCrLf & " ""issueTime"": 1537113087231," & vbCrLf & " ""price"": 0.00110001," & vbCrLf & " ""quantity"": 1733.83246562," & vbCrLf & " ""remainingQuantity"": 0.0," & vbCrLf & " ""commissionByTrade"": 0.003433," & vbCrLf & " ""bonusByTrade"": 0," & vbCrLf & " ""bonusRate"": 0," & vbCrLf & " ""commissionRate"": 0.0018," & vbCrLf & " ""lastModificationTime"": 1538092923124" & vbCrLf & " }," & vbCrLf & " {" & vbCrLf & " ""id"": 19669018551," & vbCrLf & " ""currencyPair"": ""ORME/BTC""," & vbCrLf & " ""goodUntilTime"": 0," & vbCrLf & " ""type"": ""LIMIT_SELL""," & vbCrLf & " ""orderStatus"": ""EXECUTED""," & vbCrLf & " ""issueTime"": 1537118640003," & vbCrLf & " ""price"": 4.302E-05," & vbCrLf & " ""quantity"": 1140.08057366," & vbCrLf & " ""remainingQuantity"": 0.0," & vbCrLf & " ""commissionByTrade"": 8.829E-05," & vbCrLf & " ""bonusByTrade"": 0," & vbCrLf & " ""bonusRate"": 0," & vbCrLf & " ""commissionRate"": 0.0018," & vbCrLf & " ""lastModificationTime"": 1537119048771" & vbCrLf & " }," & vbCrLf & " {" & vbCrLf & " ""id"": 19666104251," & vbCrLf & " ""currencyPair"": ""ORME/BTC""," & vbCrLf & " ""goodUntilTime"": 0," & vbCrLf & " ""type"": ""LIMIT_SELL""," & vbCrLf & " ""orderStatus"": ""PARTIALLY_FILLED_AND_CANCELLED""," & vbCrLf & " ""issueTime"": 1537116476248," & vbCrLf & " ""price"": 4.25E-05," & vbCrLf & " ""quantity"": 7487.1," & vbCrLf & " ""remainingQuantity"": 1140.08057366," & vbCrLf & " ""commissionByTrade"": 0.00048563," & vbCrLf & " ""bonusByTrade"": 0," & vbCrLf & " ""bonusRate"": 0," & vbCrLf & " ""commissionRate"": 0.0018," & vbCrLf & " ""lastModificationTime"": 1537116507585" & vbCrLf & " }," & vbCrLf & " {" & vbCrLf & " ""id"": 19661490851," & vbCrLf & " ""currencyPair"": ""ETH/BTC""," & vbCrLf & " ""goodUntilTime"": 0," & vbCrLf & " ""type"": ""LIMIT_BUY""," & vbCrLf & " ""orderStatus"": ""EXECUTED""," & vbCrLf & " ""issueTime"": 1537113025233," & vbCrLf & " ""price"": 0.03357901," & vbCrLf & " ""quantity"": 1.91066607," & vbCrLf & " ""remainingQuantity"": 0.0," & vbCrLf & " ""commissionByTrade"": 0.00011548," & vbCrLf & " ""bonusByTrade"": 0," & vbCrLf & " ""bonusRate"": 0," & vbCrLf & " ""commissionRate"": 0.0018," & vbCrLf & " ""lastModificationTime"": 1537113028429" & vbCrLf & " }," & vbCrLf & " {" & vbCrLf & " ""id"": 17637942051," & vbCrLf & " ""currencyPair"": ""ORME/BTC""," & vbCrLf & " ""goodUntilTime"": 0," & vbCrLf & " ""type"": ""LIMIT_SELL""," & vbCrLf & " ""orderStatus"": ""EXECUTED""," & vbCrLf & " ""issueTime"": 1535545801765," & vbCrLf & " ""price"": 4.5E-05," & vbCrLf & " ""quantity"": 2289.92000001," & vbCrLf & " ""remainingQuantity"": 0.0," & vbCrLf & " ""commissionByTrade"": 0.00018916," & vbCrLf & " ""bonusByTrade"": 0," & vbCrLf & " ""bonusRate"": 0," & vbCrLf & " ""commissionRate"": 0.0018," & vbCrLf & " ""lastModificationTime"": 1535545801765" & vbCrLf & " }," & vbCrLf & " {" & vbCrLf & " ""id"": 17637532551," & vbCrLf & " ""currencyPair"": ""ORME/BTC""," & vbCrLf & " ""goodUntilTime"": 0," & vbCrLf & " ""type"": ""LIMIT_SELL""," & vbCrLf & " ""orderStatus"": ""PARTIALLY_FILLED_AND_CANCELLED""," & vbCrLf & " ""issueTime"": 1535545474694," & vbCrLf & " ""price"": 4.78E-05," & vbCrLf & " ""quantity"": 2487.1," & vbCrLf & " ""remainingQuantity"": 2289.92000001," & vbCrLf & " ""commissionByTrade"": 1.697E-05," & vbCrLf & " ""bonusByTrade"": 0," & vbCrLf & " ""bonusRate"": 0," & vbCrLf & " ""commissionRate"": 0.0018," & vbCrLf & " ""lastModificationTime"": 1535545515636" & vbCrLf & " }" & vbCrLf & "]" And that sucks and hard to read. If a string contains a json, I want to see the json as it actually is. I want to be able to copy that to notepad. How do I do so?
Here is what you can do when debugging. put mouse over your variable. Popup menu will show up and there you will see magnifying lens click that Right-click on your variable, select "Quick Watch" in the menu a screen will show click magnifying lens
Translate longer excel formula to VBA function (without any cell references in VBA function)
I have this MS Excel Formula which I would like to add to as VBA function because it is too long as a normal Excel formula. It basically should create a text from different blocks of texts that are partially "dynamic" (meaning that they are partially dependent values in certain ranges and partially fixed) - based if certain conditions are met. The End formula should look something like this: "Desc()" - without having to specify any cell or range because all is defined in the formula (based on the ranges it refers to) already. IF( AND( IF(COUNTIF(Attributes,bbinput!$C$2)>0,NOT(ISBLANK(INDIRECT(bbinput!$C$2))),TRUE), IF(COUNTIF(Attributes,bbinput!$D$2)>0,NOT(ISBLANK(INDIRECT(bbinput!$D$2))),TRUE), IF(COUNTIF(Attributes,bbinput!$E$2)>0,NOT(ISBLANK(INDIRECT(bbinput!$E$2))),TRUE), IF(COUNTIF(Attributes,bbinput!$F$2)>0,NOT(ISBLANK(INDIRECT(bbinput!$F$2))),TRUE), IF(COUNTIF(Attributes,bbinput!$G$2)>0,NOT(ISBLANK(INDIRECT(bbinput!$G$2))),TRUE), IF(COUNTIF(Attributes,bbinput!$H$2)>0,NOT(ISBLANK(INDIRECT(bbinput!$H$2))),TRUE), IF(COUNTIF(Attributes,bbinput!$I$2)>0,NOT(ISBLANK(INDIRECT(bbinput!$I$2))),TRUE), IF(COUNTIF(Attributes,bbinput!$J$2)>0,NOT(ISBLANK(INDIRECT(bbinput!$J$2))),TRUE), IF(COUNTIF(Attributes,bbinput!$K$2)>0,NOT(ISBLANK(INDIRECT(bbinput!$K$2))),TRUE), LEN( TRIM( IF(COUNTIF(Attributes,bbinput!$C$2)>0,INDIRECT(bbinput!$C$2),bbinput!$C$2)&" "& IF(COUNTIF(Attributes,bbinput!$D$2)>0,INDIRECT(bbinput!$D$2),bbinput!$D$2)&" "& IF(COUNTIF(Attributes,bbinput!$E$2)>0,INDIRECT(bbinput!$E$2),bbinput!$E$2)&" "& IF(COUNTIF(Attributes,bbinput!$F$2)>0,INDIRECT(bbinput!$F$2),bbinput!$F$2)&" "& IF(COUNTIF(Attributes,bbinput!$G$2)>0,INDIRECT(bbinput!$G$2),bbinput!$G$2)&" "& IF(COUNTIF(Attributes,bbinput!$H$2)>0,INDIRECT(bbinput!$H$2),bbinput!$H$2)&" "& IF(COUNTIF(Attributes,bbinput!$I$2)>0,INDIRECT(bbinput!$I$2),bbinput!$I$2)&" "& IF(COUNTIF(Attributes,bbinput!$J$2)>0,INDIRECT(bbinput!$J$2),bbinput!$J$2)&" "& IF(COUNTIF(Attributes,bbinput!$K$2)>0,INDIRECT(bbinput!$K$2),bbinput!$K$2)&" "& IF(COUNTIF(Attributes,bbinput!$L$2)>0,INDIRECT(bbinput!$L$2),bbinput!$L$2))) <80 ), TRIM( IF(COUNTIF(Attributes,bbinput!$C$2)>0,INDIRECT(bbinput!$C$2),bbinput!$C$2)&" "& IF(COUNTIF(Attributes,bbinput!$D$2)>0,INDIRECT(bbinput!$D$2),bbinput!$D$2)&" "& IF(COUNTIF(Attributes,bbinput!$E$2)>0,INDIRECT(bbinput!$E$2),bbinput!$E$2)&" "& IF(COUNTIF(Attributes,bbinput!$F$2)>0,INDIRECT(bbinput!$F$2),bbinput!$F$2)&" "& IF(COUNTIF(Attributes,bbinput!$G$2)>0,INDIRECT(bbinput!$G$2),bbinput!$G$2)&" "& IF(COUNTIF(Attributes,bbinput!$H$2)>0,INDIRECT(bbinput!$H$2),bbinput!$H$2)&" "& IF(COUNTIF(Attributes,bbinput!$I$2)>0,INDIRECT(bbinput!$I$2),bbinput!$I$2)&" "& IF(COUNTIF(Attributes,bbinput!$J$2)>0,INDIRECT(bbinput!$J$2),bbinput!$J$2)&" "& IF(COUNTIF(Attributes,bbinput!$K$2)>0,INDIRECT(bbinput!$K$2),bbinput!$K$2)&" "& IF(COUNTIF(Attributes,bbinput!$L$2)>0,INDIRECT(bbinput!$L$2),bbinput!$L$2)), IF( AND( IF(COUNTIF(Attributes,bbinput!$C$3)>0,NOT(ISBLANK(INDIRECT(bbinput!$C$3))),TRUE), IF(COUNTIF(Attributes,bbinput!$D$3)>0,NOT(ISBLANK(INDIRECT(bbinput!$D$3))),TRUE), IF(COUNTIF(Attributes,bbinput!$E$3)>0,NOT(ISBLANK(INDIRECT(bbinput!$E$3))),TRUE), IF(COUNTIF(Attributes,bbinput!$F$3)>0,NOT(ISBLANK(INDIRECT(bbinput!$F$3))),TRUE), IF(COUNTIF(Attributes,bbinput!$G$3)>0,NOT(ISBLANK(INDIRECT(bbinput!$G$3))),TRUE), IF(COUNTIF(Attributes,bbinput!$H$3)>0,NOT(ISBLANK(INDIRECT(bbinput!$H$3))),TRUE), IF(COUNTIF(Attributes,bbinput!$I$3)>0,NOT(ISBLANK(INDIRECT(bbinput!$I$3))),TRUE), IF(COUNTIF(Attributes,bbinput!$J$3)>0,NOT(ISBLANK(INDIRECT(bbinput!$J$3))),TRUE), IF(COUNTIF(Attributes,bbinput!$K$3)>0,NOT(ISBLANK(INDIRECT(bbinput!$K$3))),TRUE), LEN( TRIM( IF(COUNTIF(Attributes,bbinput!$C$3)>0,INDIRECT(bbinput!$C$3),bbinput!$C$3)&" "& IF(COUNTIF(Attributes,bbinput!$D$3)>0,INDIRECT(bbinput!$D$3),bbinput!$D$3)&" "& IF(COUNTIF(Attributes,bbinput!$E$3)>0,INDIRECT(bbinput!$E$3),bbinput!$E$3)&" "& IF(COUNTIF(Attributes,bbinput!$F$3)>0,INDIRECT(bbinput!$F$3),bbinput!$F$3)&" "& IF(COUNTIF(Attributes,bbinput!$G$3)>0,INDIRECT(bbinput!$G$3),bbinput!$G$3)&" "& IF(COUNTIF(Attributes,bbinput!$H$3)>0,INDIRECT(bbinput!$H$3),bbinput!$H$3)&" "& IF(COUNTIF(Attributes,bbinput!$I$3)>0,INDIRECT(bbinput!$I$3),bbinput!$I$3)&" "& IF(COUNTIF(Attributes,bbinput!$J$3)>0,INDIRECT(bbinput!$J$3),bbinput!$J$3)&" "& IF(COUNTIF(Attributes,bbinput!$K$3)>0,INDIRECT(bbinput!$K$3),bbinput!$K$3)&" "& IF(COUNTIF(Attributes,bbinput!$L$3)>0,INDIRECT(bbinput!$L$3),bbinput!$L$3))) <80 ), TRIM( IF(COUNTIF(Attributes,bbinput!$C$3)>0,INDIRECT(bbinput!$C$3),bbinput!$C$3)&" "& IF(COUNTIF(Attributes,bbinput!$D$3)>0,INDIRECT(bbinput!$D$3),bbinput!$D$3)&" "& IF(COUNTIF(Attributes,bbinput!$E$3)>0,INDIRECT(bbinput!$E$3),bbinput!$E$3)&" "& IF(COUNTIF(Attributes,bbinput!$F$3)>0,INDIRECT(bbinput!$F$3),bbinput!$F$3)&" "& IF(COUNTIF(Attributes,bbinput!$G$3)>0,INDIRECT(bbinput!$G$3),bbinput!$G$3)&" "& IF(COUNTIF(Attributes,bbinput!$H$3)>0,INDIRECT(bbinput!$H$3),bbinput!$H$3)&" "& IF(COUNTIF(Attributes,bbinput!$I$3)>0,INDIRECT(bbinput!$I$3),bbinput!$I$3)&" "& IF(COUNTIF(Attributes,bbinput!$J$3)>0,INDIRECT(bbinput!$J$3),bbinput!$J$3)&" "& IF(COUNTIF(Attributes,bbinput!$K$3)>0,INDIRECT(bbinput!$K$3),bbinput!$K$3)&" "& IF(COUNTIF(Attributes,bbinput!$L$3)>0,INDIRECT(bbinput!$L$3),bbinput!$L$3)), IF( AND( IF(COUNTIF(Attributes,bbinput!$C$4)>0,NOT(ISBLANK(INDIRECT(bbinput!$C$4))),TRUE), IF(COUNTIF(Attributes,bbinput!$D$4)>0,NOT(ISBLANK(INDIRECT(bbinput!$D$4))),TRUE), IF(COUNTIF(Attributes,bbinput!$E$4)>0,NOT(ISBLANK(INDIRECT(bbinput!$E$4))),TRUE), IF(COUNTIF(Attributes,bbinput!$F$4)>0,NOT(ISBLANK(INDIRECT(bbinput!$F$4))),TRUE), IF(COUNTIF(Attributes,bbinput!$G$4)>0,NOT(ISBLANK(INDIRECT(bbinput!$G$4))),TRUE), IF(COUNTIF(Attributes,bbinput!$H$4)>0,NOT(ISBLANK(INDIRECT(bbinput!$H$4))),TRUE), IF(COUNTIF(Attributes,bbinput!$I$4)>0,NOT(ISBLANK(INDIRECT(bbinput!$I$4))),TRUE), IF(COUNTIF(Attributes,bbinput!$J$4)>0,NOT(ISBLANK(INDIRECT(bbinput!$J$4))),TRUE), IF(COUNTIF(Attributes,bbinput!$K$4)>0,NOT(ISBLANK(INDIRECT(bbinput!$K$4))),TRUE), LEN( TRIM( IF(COUNTIF(Attributes,bbinput!$C$4)>0,INDIRECT(bbinput!$C$4),bbinput!$C$4)&" "& IF(COUNTIF(Attributes,bbinput!$D$4)>0,INDIRECT(bbinput!$D$4),bbinput!$D$4)&" "& IF(COUNTIF(Attributes,bbinput!$E$4)>0,INDIRECT(bbinput!$E$4),bbinput!$E$4)&" "& IF(COUNTIF(Attributes,bbinput!$F$4)>0,INDIRECT(bbinput!$F$4),bbinput!$F$4)&" "& IF(COUNTIF(Attributes,bbinput!$G$4)>0,INDIRECT(bbinput!$G$4),bbinput!$G$4)&" "& IF(COUNTIF(Attributes,bbinput!$H$4)>0,INDIRECT(bbinput!$H$4),bbinput!$H$4)&" "& IF(COUNTIF(Attributes,bbinput!$I$4)>0,INDIRECT(bbinput!$I$4),bbinput!$I$4)&" "& IF(COUNTIF(Attributes,bbinput!$J$4)>0,INDIRECT(bbinput!$J$4),bbinput!$J$4)&" "& IF(COUNTIF(Attributes,bbinput!$K$4)>0,INDIRECT(bbinput!$K$4),bbinput!$K$4)&" "& IF(COUNTIF(Attributes,bbinput!$L$4)>0,INDIRECT(bbinput!$L$4),bbinput!$L$4))) <80 ), TRIM( IF(COUNTIF(Attributes,bbinput!$C$4)>0,INDIRECT(bbinput!$C$4),bbinput!$C$4)&" "& IF(COUNTIF(Attributes,bbinput!$D$4)>0,INDIRECT(bbinput!$D$4),bbinput!$D$4)&" "& IF(COUNTIF(Attributes,bbinput!$E$4)>0,INDIRECT(bbinput!$E$4),bbinput!$E$4)&" "& IF(COUNTIF(Attributes,bbinput!$F$4)>0,INDIRECT(bbinput!$F$4),bbinput!$F$4)&" "& IF(COUNTIF(Attributes,bbinput!$G$4)>0,INDIRECT(bbinput!$G$4),bbinput!$G$4)&" "& IF(COUNTIF(Attributes,bbinput!$H$4)>0,INDIRECT(bbinput!$H$4),bbinput!$H$4)&" "& IF(COUNTIF(Attributes,bbinput!$I$4)>0,INDIRECT(bbinput!$I$4),bbinput!$I$4)&" "& IF(COUNTIF(Attributes,bbinput!$J$4)>0,INDIRECT(bbinput!$J$4),bbinput!$J$4)&" "& IF(COUNTIF(Attributes,bbinput!$K$4)>0,INDIRECT(bbinput!$K$4),bbinput!$K$4)&" "& IF(COUNTIF(Attributes,bbinput!$L$4)>0,INDIRECT(bbinput!$L$4),bbinput!$L$4)), ))) I have the following code in VBA already: "=IF(" & Chr(10) & "AND(" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C3)>0,NOT(ISBLANK(INDIRECT(bbinput!R2C3))),TRUE)," & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C4)>0,NOT(ISBLANK(INDIRECT(bbinput!R2C4))),TRUE)," & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C5)>0,NOT(ISBLANK(INDIRECT(bbinput!R2C5))),TRUE)," & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C6)>0,NOT(ISBLANK(INDIRECT(bbinput!R2C6))),TRUE)," & Chr(10) & "IF(COUNTIF(Attributes,bbinput!" & _ "R2C7)>0,NOT(ISBLANK(INDIRECT(bbinput!R2C7))),TRUE)," & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C8)>0,NOT(ISBLANK(INDIRECT(bbinput!R2C8))),TRUE)," & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C9)>0,NOT(ISBLANK(INDIRECT(bbinput!R2C9))),TRUE)," & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C10)>0,NOT(ISBLANK(INDIRECT(bbinput!R2C10))),TRUE)," & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C11)>0,NOT(ISBLANK(INDIRECT(bbinput!" & _ "R2C11))),TRUE)," & Chr(10) & "" & Chr(10) & "LEN(" & Chr(10) & "TRIM(" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C3)>0,INDIRECT(bbinput!R2C3),bbinput!R2C3)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C4)>0,INDIRECT(bbinput!R2C4),bbinput!R2C4)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C5)>0,INDIRECT(bbinput!R2C5),bbinput!R2C5)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C6)>0,INDIRECT(bbinput!R2C6),bbinput!R2C6)&"" ""&" & Chr(10) & "IF(COUNTIF(A" & _ "ttributes,bbinput!R2C7)>0,INDIRECT(bbinput!R2C7),bbinput!R2C7)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C8)>0,INDIRECT(bbinput!R2C8),bbinput!R2C8)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C9)>0,INDIRECT(bbinput!R2C9),bbinput!R2C9)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C10)>0,INDIRECT(bbinput!R2C10),bbinput!R2C10)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C11)>0,INDIRECT(b" & _ "binput!R2C11),bbinput!R2C11)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C12)>0,INDIRECT(bbinput!R2C12),bbinput!R2C12)))" & Chr(10) & "<80" & Chr(10) & ")," & Chr(10) & "" & Chr(10) & "TRIM(" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C3)>0,INDIRECT(bbinput!R2C3),bbinput!R2C3)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C4)>0,INDIRECT(bbinput!R2C4),bbinput!R2C4)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C5)>0,INDIRECT(bbinput!R2C5),bbinput!R2C5)" & _ "&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C6)>0,INDIRECT(bbinput!R2C6),bbinput!R2C6)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C7)>0,INDIRECT(bbinput!R2C7),bbinput!R2C7)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C8)>0,INDIRECT(bbinput!R2C8),bbinput!R2C8)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C9)>0,INDIRECT(bbinput!R2C9),bbinput!R2C9)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2" & _ "C10)>0,INDIRECT(bbinput!R2C10),bbinput!R2C10)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C11)>0,INDIRECT(bbinput!R2C11),bbinput!R2C11)&"" ""&" & Chr(10) & "IF(COUNTIF(Attributes,bbinput!R2C12)>0,INDIRECT(bbinput!R2C12),bbinput!R2C12)),"
This does the first bit - I'm going home shortly so I've run out of time - but this might get you started :-) public function Desc() as string dim s as string dim r as range dim att as range set att = range("attributes") dim ok as boolean for each r in worksheets("bbinput").range("c2:k2") if application.worksheetfunction.counta(att,r)>0 then s = s & range(r.text) & " " end if next r desc=s end function
Format Exception Error when writing text to a file in VB
When I try to write text to a file, I get an error saying "FormatException was unhandled" Here's the code: Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Dim ChampPath As String = FolderBrowserDialog1.SelectedPath & "\League of Legends\Config\Champions" Dim NamePath As String = ChampPath & "\" & SelectChampion.Text Dim FilePath As String = NamePath & "\" & SelectChampion.Text & ".json" Dim Map As String Dim Mode As String System.IO.Directory.CreateDirectory(NamePath) System.IO.File.Create(FilePath).Dispose() If (SelectMap.Text = "Any") Then Map = "any" ElseIf (SelectMap.Text = "Summoners Rift") Then Map = "1" ElseIf (SelectMap.Text = "Twisted Treeline") Then Map = "10" ElseIf (SelectMap.Text = "Crystal Scar") Then Map = "8" ElseIf (SelectMap.Text = "Proving Grounds") Then Map = "3" End If If (SelectMode.Text = "Any") Then Mode = "any" ElseIf (SelectMode.Text = "Classic") Then Mode = "CLASSIC" ElseIf (SelectMode.Text = "Dominon") Then Mode = "ODIN" ElseIf (SelectMode.Text = "Proving Grounds") Then Mode = "ARAM" End If If (System.IO.File.Exists(FilePath)) Then Using Writer As StreamWriter = New StreamWriter(FilePath) Writer.Write("{" & vbNewLine & " ""champion"":""" & SelectChampion.Text & """," & vbNewLine & " ""title"":""" & TitleBox.Text & "", " " & vbNewLine & " ""type"":""" & TypeBox.Text & "", " " & vbNewLine & " ""map"":""" & Map & "", " " & vbNewLine & " ""mode"":""" & Mode & "", " " & vbNewLine & " ""priority""" & SelectPriority.Text & "", " " & vbNewLine & " ""blocks"":[ " & vbNewLine & "{" & vbNewLine & " ""type"":""starting"", " & vbNewLine & " ""items"":[ " & vbNewLine & "{" & vbNewLine & " ""id"":""1001"", " & vbNewLine & " ""count"":1 " & vbNewLine & "}," & vbNewLine & "{" & vbNewLine & " ""id"":""3010"", " & vbNewLine & " ""count"":3 " & vbNewLine & "}" & vbNewLine & "]" & vbNewLine & "}," & vbNewLine & "{" & vbNewLine & " ""type"":""essential"", " & vbNewLine & " ""items"":[ " & vbNewLine & "{" & vbNewLine & " ""id"":""3001"", " & vbNewLine & " ""count"":1 " & vbNewLine & "}," & vbNewLine & "{" & vbNewLine & " ""id"":""3089"", " & vbNewLine & " ""count"":1 " & vbNewLine & "}" & vbNewLine & "]" & vbNewLine & "}," & vbNewLine & "{" & vbNewLine & " ""type"":""offensive"", " & vbNewLine & " ""items"":[ " & vbNewLine & "{" & vbNewLine & " ""id"":""3100"", " & vbNewLine & " ""count"":1 " & vbNewLine & "}," & vbNewLine & "{" & vbNewLine & " ""id"":""3128"", " & vbNewLine & " ""count"":1 " & vbNewLine & "}," & vbNewLine & "{" & vbNewLine & " ""id"":""3135"", " & vbNewLine & " ""count"":1 " & vbNewLine & "}" & vbNewLine & "]" & vbNewLine & "}," & vbNewLine & "{" & vbNewLine & " ""type"":""defensive"", " & vbNewLine & " ""items"":[ " & vbNewLine & "{" & vbNewLine & " ""id"":""3140"", " & vbNewLine & " ""count"":1 " & vbNewLine & "}," & vbNewLine & "{" & vbNewLine & " ""id"":""3157"", " & vbNewLine & " ""count"":1 " & vbNewLine & "}" & vbNewLine & "]" & vbNewLine & "}" & vbNewLine & "]" & vbNewLine & "}") End Using End If End Sub I can't find where the error is actually coming from... The text also needs to be formatted like it is, with the quotes and what not. Thanks for any help.
Assumed VB Net .. Better you change like this Writer.Write("{" & vbNewLine & _ " champion : " & SelectChampion.Text & "," & vbNewLine & _ " title : " & TitleBox.Text & "," & vbNewLine & _ " type : " ........ ...... etc