I have run into a problem trying to get this code to work:
filereader.Replace(Chr(34) & "SomeSetting" & Chr(34) & "=dword:00000000", Chr(34) & "SomeSetting" & Chr(34) & "=dword:00000001")
I want it to replace a string which is !exaclty! looking like this, containing the quotation marks:
"SomeSetting"=dword:00000000
but what it does is looking for this string:
""SomeSetting""=dword:00000000
and i cant get it to work. Even if i tried this:
Dim Test As String = Chr(34)
Test will look like this:
""
instead of "
what am i missing here?
I think I see your problem... This is a quite common, accidental thing for people to do.
Strings are immutable, which means that once you've created them they cannot be changed without creating a new string instance.
The problem is this:
filereader.Replace(Chr(34) & "SomeSetting" & Chr(34) & "=dword:00000000", Chr(34) & "SomeSetting" & Chr(34) & "=dword:00000001")
The Replace() function returns the new string with the replaced value(s) (since it cannot change the original one), but you never use the instance it returns.
You should set your old string variable to the new string returned by Replace(), like this:
filereader = filereader.Replace(Chr(34) & "SomeSetting" & Chr(34) & "=dword:00000000", Chr(34) & "SomeSetting" & Chr(34) & "=dword:00000001")
To avoid (or at least minimize the risk of) things like this happening, make sure you read the information that Visual Studio's IntelliSense shows you when writing the function call.
If you do bump into problems anyway, make sure to check the MSDN documentation to see if you missed anything. They usually also have examples showing how you can use the methods.
Related
I've tried just about everything i can think of on why i would get this error, but i have had no luck. I wrote a similar code that references that same table with numerical values that works fine, but when searching for text it has problems. The error code says the missing operator lies here: [ExpendetureStore] = 'Lowe's
TotalCostTextBox = DSum("[ExpendetureCost]", "ProjectExpendetures", "[ExpendetureStore] = '" & Me.StoreNameCombo & "'")
Lowe's has an apostrophe in its name. Access query engine is reading that apostrophe as a special character (text delimiter) in the compiled search string. If your data includes apostrophes, one way to deal with is to 'escape' the character - double it in the data with Replace() function. This forces Access to treat the character as normal text.
TotalCostTextBox = DSum("[ExpendetureCost]", "ProjectExpendetures", "[ExpendetureStore] = '" & Replace(Me.StoreNameCombo, "'", "''") & "'")
The same will happen with quote marks and are more challenging to deal with. Note the escaping of quote between quotes.
Replace("somevalue", """", """" & """")
Or may be easier to understand using Chr() function.
Replace("somevalue", Chr(34), Chr(34) & Chr(34))
Side note: Expendeture is a misspelling of Expenditure.
I need to get a path from two different machine/pc, one of them is with English environment and the other with Chinese environment.
I have a project into our database with this name: Defaults侇侚
If I open my database the name is display like this:
Is the last one.
My problem is, when I'm going on the English machine/pc I receive in my application this String: "c:\Restore\20190213140908\Defaults" & ChrW(129) & "î" & ChrW(129) & "ù\Defaults" & ChrW(129) & "î" & ChrW(129) & "ù"
Everything is ok, my function return true.
But when I'm going on the Chinese machine/pc I receive this type of string:"c:\Restore\20190213142118\Defaults侇侚\Defaults侇侚" and my function doesn't work.
My question is how it's posible to convert this string:
"c:\Restore\20190213142118\Defaults侇侚\Defaults侇侚"
to
"c:\Restore\20190213140908\Defaults" & ChrW(129) & "î" & ChrW(129) & "ù\Defaults" & ChrW(129) & "î" & ChrW(129) & "ù"
Note: For this database is not possible to change the unicode.
Using access 2010, windows 7, SQL Server
Can't get the hang of this. Have an SQL query that was generated in the qbe grid then put in VBA. The version that runs has a literal Transaction_Table.Account_Number and looks like:
"WHERE (((dbo_Transaction_Table.Sku)=""Transfer"")
AND ((dbo_Transaction_Table.Description) Like ""%TO%"")
AND ((dbo_Transaction_Table.Account_Number)=""655812""));"
But when I try to replace the literal with the contents of a text box :
"WHERE (((dbo_Transaction_Table.Description) Like ""%Transfer To%"")
AND ((dbo_Transaction_Table.Account_Number)=& Chr$(34) & Me.accntNo & Chr$(34)));"`
I get a syntax err (missing operator) in query expression
(((dbo_Transaction_table.Description) like "%Transfer To%")
And ((dbo_Transaction_Table.Account_Number)= & Chr$(34) & Me.accntNo & Chr$(34))))`
It sounds like you're just missing quotes between the constant string and the injected values
"WHERE (((dbo_Transaction_Table.Description) Like ""%Transfer To%"")
AND ((dbo_Transaction_Table.Account_Number)=" & Chr$(34) & Me.accntNo & Chr$(34) & "));"
Although you might look into using parameters instead. I'm not an expert on doing those from VBA but there should be plenty of examples out there.
Compile error:Argument not optional
I am getting the above error while executing the following query:
DoCmd.RunSQL = "insert into tblContract (Empid,testid,Start1,Finish1,Store1,Start2,Finish2,Store2 )values ('" & Me.txtEmpNo.Value & "','" & Me.txtAutoNumber.Value & "','" & Me.txtContSunStart1.Value & "', '" & Me.txtContSunFinish1.Value & "','" & Me.txtContSunStore1.Value & "','" & Me.txtContSunStart2.Value & "', '" & Me.txtContSunFinish2.Value & "','" & Me.txtContSunStore2.Value & "')"
Please help
DoCmd.RunSQL is a method not a property. You don't do "DoCmd.RunSQL = SomeSQL" You do "DoCmd.RunSQL someSQL" (no equals sign).
DoCmd.RunSQL has very poor error handling and comes back with uninformative error messages. You will find it much easier to debug or trap errors using CurrentDB.Execute
Have you really got DoCmd.RunSQL = someString ? With that = in there? It won't like that...
Assuming your syntax is correct, you most likely have a field that requires a value but you've omitted from your target field list. That is a field in the table designer has the "Required" set to Yes in the General tab.
If you don't think that this is it, I'd probably need a little more info on the schema or perhaps the query.
This may not be the issue. But you may want to make sure your input does not contain a single quote. For example, if Me.txtContSunStore1 equals something like "Bob's Store", that line will complain. Though it would probably give you a different error.
I usually wrap all SQL Values with a function that cleans up the data based on the data type.
Try add space before values.
As Oorang said remove the = sign
EDIT: Also please check if everyfields are text type. I would guess Empid and testid fields are numeric...
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.