Visual Basic- "IF" doesn't end - vb.net

If My.Computer.FileSystem.FileExists("pack/locale_ro.epk") Then My.Computer.FileSystem.DeleteFile("pack/locale_ro.epk")
PB_GSM.Value = 10
If My.Computer.FileSystem.FileExists("pack/locale_ro.eix") Then My.Computer.FileSystem.DeleteFile("pack/locale_ro.eix")
PB_GSM.Value = 20
If My.Computer.FileSystem.FileExists("pack/root.epk") Then My.Computer.FileSystem.DeleteFile("pack/root.epk")
PB_GSM.Value = 30
If My.Computer.FileSystem.FileExists("pack/root.eix") Then My.Computer.FileSystem.DeleteFile("pack/root.eix")
PB_GSM.Value = 40
My.Computer.Network.DownloadFile("http://example")
I believe i wrote everything correct, but it doesn't matter how i write the "if"-s , i can not end them. if i wrote End if next to a line it says something like "End if must be preceded by a matching if".
And another problem , the line about the download link is underlined and it says"Overload resolution failed because no accessible 'DownloadFile' accepts this number of arguments".
P.S: this is a try for a metin2 patcher, i do not know exactly how to do it but i'm sure this is a way to update the game only at the files that i neeed.Thanks for help:)

You have them all in one line. Don't put anything after the "Then" keyword.
If My.Computer.FileSystem.FileExists("pack/locale_ro.epk") Then
My.Computer.FileSystem.DeleteFile("pack/locale_ro.epk")
PB_GSM.Value = 10
End If
If looking for an else-if situation, this would be the syntax:
If My.Computer.FileSystem.FileExists("pack/locale_ro.epk") Then
My.Computer.FileSystem.DeleteFile("pack/locale_ro.epk")
PB_GSM.Value = 10
ElseIf My.Computer.FileSystem.FileExists("pack/locale_ro.eix") Then
My.Computer.FileSystem.DeleteFile("pack/locale_ro.eix")
PB_GSM.Value = 20
' etc, etc
End If
Note though that this will only run the code on the first "True" line found.
For the DownloadFile, you also need to specify the destination:
My.Computer.Network.DownloadFile("http://example", "c:\temp\myfile.txt")
Substitute the c:\temp\ path with the one you are using.

When you post the Then statement followed by an expression that closes that If statement. You have, in essence, already closed all your If statements.

Related

Having Issue on Field Calculator With Python in ArcMap

I have tried all of below snippets to use Python Parser in Field Calculator and update the values of a field called type based on a filed called MamerMN but in all of them I am getting Syntax error in Geoprocessing result window!
if !MamerMN! <= 0.151560:
return 1
and
if (!MamerMN! <= 0.151560):
return 1
and
if (MamerMN <= 0.151560):
return 1
and
def(MamerMN)
if MamerMN <= 0.151560:
return 1
and
def(MamerMN)
if (MamerMN <= 0.151560):
return 1
Can you please let me know what I am doing wrong?
You are writing your functions wrong. In the Field Calculator, make sure you check 'Show Codeblock' so the Pre-Logic Script Code box appears. Inside the Pre-Logic box, write your function-
def calcValue(mamerMN):
if mamerMN <= 0.151560:
return 1
and then in the box under, where it says the field_name =
you should write the name of the function and the field value you are passing to it surrounded by exclamations. So if your function above is named calcValue you would write
calcValue(!mamerMN!)
Without seeing a graphic of what your Field Calculator looks like, I suspect #csterling is probably right. However, an alternative is to just Select by Attribute where "mamerMN" <= 0.151560, then Field Calculate your selected features to 1 the regular way without necessitating a codeblock.

Parse SQL with REGEX to find Physical Update

I've spent a bit of time trying to bend regex to my will but its beaten me.
Here's the problem, for the following text...
--to be matched
UPDATE dbo.table
UPDATE TOP 10 PERCENT dbo.table
--do not match
UPDATE #temp
UPDATE TOP 10 PERCENT #temp
I'd like to match the first two updates statements and not match the last two update statements. So far I have the regex...
UPDATE\s?\s+[^#]
I've been trying to get the regex to ignore the TOP 10 PERCENT part as its just gets in the way. But I haven't been successful.
Thanks in advance.
I'm using .net 3.5
I assume you're trying to parse real SQL syntax (looks like SQL Server) so I've tried something that is more suitable for that (rather than just detecting the presence of #).
You can try regex like:
UPDATE\s+(TOP.*?PERCENT\s+)?(?!(#|TOP.*?PERCENT|\s)).*
It checks for UPDATE followed by optional TOP.*?PERCENT and then by something that is not TOP.*?PERCENT and doesn't start with #. It doesn't check just for the presence of # as this may legitimately appear in other position and not mean a temp table.
As I understand it, you want a regex to interact with SQL code, not actually querying a database?
You can use a negative look ahead to check if the line has #temp:
(?m)^(?!.*#temp).*UPDATE
(?!...) will fail the whole match if what's inside it matches, ^ matches the beginning of the line when combined with the m modifier. (?m) is the inline version of this modifier, as I don't know how/where you plan on using the regex.
See demo here.
#Robin's solution is much better but in case you needed regex with some simplier mechanisms employed I give you this:
UPDATE\s+(TOP\s+10\s+PERCENT\s+)?[a-z\.]+
sqlconsumer, here's a fully functioning C# .NET program. Does it do what you're looking for?
using System;
using System.Text.RegularExpressions;
class Program {
static void Main() {
string s1 = "UPDATE dbo.table";
string s2 = "UPDATE TOP 10 PERCENT dbo.table";
string s3 = "UPDATE #temp";
string s4 = "UPDATE TOP 10 PERCENT #temp";
string pattern = #"UPDATE\s+(?:TOP 10 PERCENT\s+)?dbo\.\w+";
Console.WriteLine(Regex.IsMatch(s1, pattern) );
Console.WriteLine(Regex.IsMatch(s2, pattern));
Console.WriteLine(Regex.IsMatch(s3, pattern));
Console.WriteLine(Regex.IsMatch(s4, pattern));
Console.WriteLine("\nPress Any Key to Exit.");
Console.ReadKey();
} // END Main
} // END Program
The Output:
True
True
False
False

create variable as a function of another variable in SQL

Okay. Basically, I want to define a complex variable within a SQL statement and then define another variable as a "function" of the first. I've searched around and can find no indication of how I might accomplish this. I can always just copypaste the code, but that makes it SO messy! See my (erroneous) example below. true file is the first variable and location is the second.
select
true_file = RIGHT(url.FULL_PATH, CHARINDEX('/',REVERSE(url.FULL_PATH)) - 1),
location = RIGHT(url.FULL_PATH, LEN(url.FULL_PATH) - LEN(true_file) - 9)
from files f
join BBLEARN_cms_doc.dbo.XYF_URLS url
on url.FILE_ID = substring(f.file_name, 6, len(f.file_name) - 7)
where f.file_name like '/xid-%'
order by url.FULL_PATH;
But obviously, we get an "invalid column name" error when trying to run any functions on true_file. What's the best way to do this?

Rally Excel Plugin Queries

I am working with the Rally/Excel plug-in and setting up queries/filters for our various delivery teams. One of the teams is named "Agency / L&C". The & is causing me all sorts of problems that I cannot seem to get past. The current filter is:
((Release.Name = "2013 November") AND (Project.Name = "Agency / L&C"))
When I execute the query I get this error:
Query failed due to errors:
Could not parse: Cannot parse expression "((Release.Name = "2013 November") AND (Project.Name = "Agency / L" as a query
I have tried several things, ' before and after, '' before and after, %, " and \ and nothing seems to be making it register the & as text.
Thanks for the help
This is an educated guess but I would think the problem arises from the ampersand not being escaped before the request is made to the to the API. You might try changing it to "%26" (the HTML code for "&") and see what you get.

Why am I getting the Missing Operator error?

I keep getting the same error: Missing Operator. I have looked over this code three times and cannot find it. Can someone with a keen eye please help?
WHERE ([Letter Status].[Letter_Status] = “Agreed” AND [Research].[Site] = 9)
OR ([Telephone Status].[Details]= “Agreed” AND [Research].[Site] = 9)
I'm not sure about that “”
Maybe is from this post, but change them to "" :
WHERE ([Letter Status].[Letter_Status] = "Agreed" AND [Research].[Site] = 9)
OR ([Telephone Status].[Details]= "Agreed" AND [Research].[Site] = 9)
Usually it is a misspelled table or field name, two spaces instead of just one, a space instead of "_", any missing letter or something like that.
Create a new query in MS Access and put the whole query in, then run it. The Access GUI most probably tells you more detailed what exactly is missing here.