I have a class that currently works like this.
Class Maze
Public board(10, 10) As Object
Dim maze1 As New Maze With {.board = {{" ", " ", "X", "X", " ", "X", "X", "X", " ", "X"},
{"X", " ", " ", " ", " ", "X", " ", " ", " ", "X"},
{" ", " ", "X", " ", "X", " ", " ", " ", " ", "X"},
{"X", " ", "X", " ", " ", "X", "X", "X", " ", " "},
{"X", " ", "X", "X", " ", " ", " ", " ", "X", " "},
{" ", "X", " ", " ", "X", " ", " ", "X", " ", " "},
{" ", "X", "X", " ", "X", " ", " ", " ", " ", "X"},
{" ", " ", " ", " ", " ", "X", "X", " ", " ", "X"},
{"X", "X", " ", "X", " ", " ", " ", "X", " ", " "},
{" ", " ", " ", "X", "X", " ", " ", " ", "X", " "}}}
However I cant find away to remove the prespecified length without methods such as GetLength now not working.
In the .Net world, if you define a type as Object you're almost always doing something very wrong you will soon come to regret. In this case, it looks like String may be more appropriate. However, perhaps based on how this is used later it might turn out that Integer or a specific class type could be better, alongside a special method to translate this into text or graphics for output.
Moving on to the specific issue of size... consider a List:
Class Maze
Dim board As List(Of List(Of String))
board = New List(Of List(Of string)) From {
New List(Of String) From {" ", " ", "X", "X", " ", "X", "X", "X", " ", "X"},
New List(Of String) From {"X", " ", " ", " ", " ", "X", " ", " ", " ", "X"},
New List(Of String) From {" ", " ", "X", " ", "X", " ", " ", " ", " ", "X"},
New List(Of String) From {"X", " ", "X", " ", " ", "X", "X", "X", " ", " "},
New List(Of String) From {"X", " ", "X", "X", " ", " ", " ", " ", "X", " "},
New List(Of String) From {" ", "X", " ", " ", "X", " ", " ", "X", " ", " "},
New List(Of String) From {" ", "X", "X", " ", "X", " ", " ", " ", " ", "X"},
New List(Of String) From {" ", " ", " ", " ", " ", "X", "X", " ", " ", "X"},
New List(Of String) From {"X", "X", " ", "X", " ", " ", " ", "X", " ", " "},
New List(Of String) From {" ", " ", " ", "X", "X", " ", " ", " ", "X", " "}
}
Now you can add a line to end like so:
board.Add(New List(Of String) From {" ", "X", " ", " ", " " ... })
Or add a column like this:
For Each c As List(Of String) In board
c.Add(" ")
Next
This allows you to have 2d array without specifying length explicitly
Public board(,) As Object = {}
Related
Module Program
Dim startx As Integer
Dim starty As Integer
Dim endx As Integer
Dim endy As Integer
Dim maze As String(,) = {
{"x ", "x ", "x ", "x ", "x ", "x ", "x ", "x ", "x ", "x"},
{"O ", " ", " ", " ", " ", " ", " ", " ", " ", "x"},
{"x ", "x ", "x ", "x ", "x ", " ", "x ", "x ", " ", "x"},
{"x ", "x ", " ", "x ", "x ", " ", "x ", "x ", " ", "x"},
{"x ", "x ", " ", " ", " ", " ", "x ", "x ", " ", "x"},
{"x ", "x ", "x ", "x ", "x ", " ", "x ", "x ", "x ", "x"},
{"x ", " ", " ", " ", " ", " ", " ", " ", " ", "x"},
{"x ", " ", "x ", "x ", "x ", "x ", "x ", "x ", " ", "x"},
{"x ", " ", " ", " ", " ", "x ", "x ", "x ", " ", " "},
{"x ", "x ", "x ", "x ", "x ", "x ", "x ", "x ", "x ", "x"}}
Sub Main(args As String())
Console.WriteLine("This is a maze game")
Console.WriteLine("Please enter where you want to go (x and y cordinate)")
start
displaychessboard()
End Sub
Sub displaychessboard()
Console.WriteLine(" 0 1 2 3 4 5 6 7 8 9")
For x As Integer = 0 To 9
Console.Write(x & " ")
For y As Integer = 0 To 9
Console.Write(maze(x, y))
Next
Console.WriteLine()
Next
End Sub
Sub makemove()
End Sub
End Module
How do I move the position of the player based on user input.
You store the position of a player in one or more variables. Since you have a two-dimensional maze, you can use a two-element tuple or, for simplicity, a player_x and a player_y variable.
When the user provides input, you modify the variables accordingly. For example, "moving left" would decrease player_x by one.
When drawing your maze, you look at the current values of player_x and player_y. If they match the current position in your loop, you output "O" instead of a space.
Pls answer in vb
The Stack Overflow community will gladly help you understand concepts and teach you how to improve your Visual Basic skills, but we are not a "here is my task, you write code" service.
I'm creating a utility for a game that creates spreadsheets of data by reading the game's code.
One of the most basic aspects of this is being able to read the game's code efficiently. The game is written in C#. I'm using VB.Net for my program because my mind can't grasp the abstraction of more complex languages. Historically the way I had my program recognise code blocks in the code text file is by counting the brackets that encapsulated them and working off of that. This seems a bit clunky, though. Is there any simpler way to help the program figure out code blocks?
For Example, code in the text file might look like this:
6673={
key="d_example_duchy_1"
de_facto_liege=12
variables={
data={ {
flag="traditional_de_jure_kingdom"
tick=0
data={
type=lt
identity=6632
}
}
}
}
de_jure_liege=6632
de_jure_vassals={ 6674 6678 6682 6686 }
holder=558
name="Example Duchy 1"
date=1253.1.1
heir={ 880 }
history={ 1253.1.1=558 }
capital=6674
history_government="tribal_government"
coat_of_arms_id=2320
}
6674={
key="c_example_county_1"
variables={
data={ {
flag="influx_culture"
tick=0
data={
type=culture
identity=11
}
}
{
flag="influx_faith"
tick=0
data={
type=faith
identity=57
}
}
{
flag="fog_resistance"
tick=0
data={
type=value
}
}
}
}
de_jure_liege=6673
de_jure_vassals={ 6675 6676 6677 }
holder=558
name="Example County 1"
date=1243.6.26
heir={ 880 }
capital=6674
coat_of_arms_id=2323
}
6675={
key="b_example_barony_1"
de_facto_liege=6674
de_jure_liege=6674
holder=558
name="Example Barony 1"
date=1254.1.1
capital_barony=yes
duchy_capital_barony=yes
capital=6674
coat_of_arms_id=2328
}
6676={
key="b_example_barony_2"
de_facto_liege=6674
de_jure_liege=6674
holder=11609
name="Example Barony 2"
date=1253.7.28
capital=6674
coat_of_arms_id=2332
}
6677={
key="b_example_barony_3"
de_facto_liege=6674
de_jure_liege=6674
holder=558
name="Example Barony 3"
date=1232.2.8
heir={ 880 }
capital=6674
theocratic_lease=yes
coat_of_arms_id=2334
}
Thanks in advance. :)
The solution I eventually settled on, for discerning the overall code-blocks (e.g. all the data nested under 6674={ ... }) was basically:
Dim Code As String = File.ReadAllText("PATH/TO/CODE/FILE.txt")
Dim Output As List(Of String) = Code.Split(vbCrLf & "}" & vbCrLf).ToList
So in plain English, reading all the code into a single string, then splitting the string according to how the original code's language distinguished the initial nest of code (i.e. a carriage return followed by a curly bracket followed by another carriage return).
The list at the end would look something like this:
Output(0)
6673={" & vbCrLf & " key=""d_example_duchy_1""" & vbCrLf & " de_facto_liege=12" & vbCrLf & " variables={" & vbCrLf & " data={ {" & vbCrLf & " flag=""traditional_de_jure_kingdom""" & vbCrLf & " tick=0" & vbCrLf & " data={" & vbCrLf & " type=lt" & vbCrLf & " identity=6632" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " de_jure_liege=6632" & vbCrLf & " de_jure_vassals={ 6674 6678 6682 6686 }" & vbCrLf & " holder=558" & vbCrLf & " name=""Example Duchy 1""" & vbCrLf & " date=1253.1.1" & vbCrLf & " heir={ 880 }" & vbCrLf & " history={ 1253.1.1=558 }" & vbCrLf & " capital=6674" & vbCrLf & " history_government=""tribal_government""" & vbCrLf & " coat_of_arms_id=2320
Output(1)
6674={" & vbCrLf & " key=""c_example_county_1""" & vbCrLf & " variables={" & vbCrLf & " data={ {" & vbCrLf & " flag=""influx_culture""" & vbCrLf & " tick=0" & vbCrLf & " data={" & vbCrLf & " type=culture" & vbCrLf & " identity=11" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " {" & vbCrLf & " flag=""influx_faith""" & vbCrLf & " tick=0" & vbCrLf & " data={" & vbCrLf & " type=faith" & vbCrLf & " identity=57" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " {" & vbCrLf & " flag=""fog_resistance""" & vbCrLf & " tick=0" & vbCrLf & " data={" & vbCrLf & " type=value" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " }" & vbCrLf & " de_jure_liege=6673" & vbCrLf & " de_jure_vassals={ 6675 6676 6677 }" & vbCrLf & " holder=558" & vbCrLf & " name=""Example County 1""" & vbCrLf & " date=1243.6.26" & vbCrLf & " heir={ 880 }" & vbCrLf & " capital=6674" & vbCrLf & " coat_of_arms_id=2323
And so on with the remaining three.
I am trying to translate Morse code into text in VB.net.
Using below code, some of the letters in the text stays untranslated. I believe the problem is with "oddel" which should indicated how many letters should be cut in Mid(morsC, i, oddel), while selecting the case.
Code should be able to translate this >…./ ./ .-../ .-../ ---/< into Hello.
What's weird is that while translating "Hello", first letter "H" is correctly cut as " ..../" but it's not matched with the Case "H"
'Hello = …./ ./ .-../ .-../ ---/
Sub EE15a()
Dim veta As String, morsCod As String, st As String
morsCod = InputBox("Enter the morse code.")
veta = morsCodF(morsCod)
st = "Preklad dle funkce " + Chr(10) + veta + Chr(10)
MsgBox(st)
End Sub
Function morsCodF(morsC As String) As String
Dim pismeno As String, znak As String
Dim i As Integer, j As Integer, oddel As Integer
Dim nasel As Boolean
znak = "/"
morsC = Trim(morsC)
j = 1
For i = 1 To (morsC.Length)
i = j
Do
If Mid(morsC, j, 1) = znak Then
oddel = j - oddel
nasel = True
Exit Do
End If
j = j + 1
Loop Until nasel = True Or j > (morsC.Length)
If i = 1 Then
pismeno = (" " + Mid(morsC, i, oddel))
Else
pismeno = Mid(morsC, i, oddel)
End If
Select Case pismeno '" ...-/"
Case " .-/" : morsCodF = morsCodF + " a"
Case " -.../" : morsCodF = morsCodF + " b"
Case " -.-./" : morsCodF = morsCodF + " c"
Case " -../" : morsCodF = morsCodF + " d"
Case " ./" : morsCodF = morsCodF + " e"
Case " ..-./" : morsCodF = morsCodF + " f"
Case " --./" : morsCodF = morsCodF + " g"
Case " ..../" : morsCodF = morsCodF + " h"
Case " ../" : morsCodF = morsCodF + " i"
Case " .---/" : morsCodF = morsCodF + " j"
Case " -.-/" : morsCodF = morsCodF + " k"
Case " .-../" : morsCodF = morsCodF + " l"
Case " --/" : morsCodF = morsCodF + " m"
Case " -./" : morsCodF = morsCodF + " n"
Case " ---/" : morsCodF = morsCodF + " o"
Case " .--./" : morsCodF = morsCodF + " p"
Case " --.-/" : morsCodF = morsCodF + " q"
Case " .-./" : morsCodF = morsCodF + " r"
Case " .../" : morsCodF = morsCodF + " s"
Case " -/" : morsCodF = morsCodF + " t"
Case " ..-/" : morsCodF = morsCodF + " u"
Case " ...-/" : morsCodF = morsCodF + " v"
Case " .--/" : morsCodF = morsCodF + " w"
Case " -..-/" : morsCodF = morsCodF + " x"
Case " -.--/" : morsCodF = morsCodF + " y"
Case " --../" : morsCodF = morsCodF + " z"
Case "#" : morsCodF = morsCodF + " "
End Select
nasel = False
pismeno = ""
j = j + 1
Next
End Function
Code should translate whole word or sentence, but instead is translating only part of the text. E.g. > …./ ./ .-../ .-../ ---/
expected: "Hello", actual: "e o"
split the string morsCod with "/" as separator
Public Class Form1
Sub EE15a()
Dim veta As String, morsCod As String, st As String
'morsCod = InputBox("Enter the morse code.")
morsCod = "..../ ./ .-../ .-../ ---/ --"
morsCod = " .-/ -.../ -.-./ -../ ./ ..-./ --./ ..../ ../ .---/ -.-/ .-../ --/ -./ ---/ .--./ --.-/ .-./ .../ -/ ..-/ ...-/ .--/ -..-/ -.--/ --.."
veta = morsCodF(morsCod)
st = "Preklad dle funkce " + Chr(10) + veta + Chr(10)
MsgBox(st)
End Sub
Function morsCodF(morsC As String) As String
Dim arr As String() = morsC.Split("/"c)
For Each s As String In arr
Select Case s
Case " .-" : morsCodF = morsCodF + " a"
Case " -..." : morsCodF = morsCodF + " b"
Case " -.-." : morsCodF = morsCodF + " c"
Case " -.." : morsCodF = morsCodF + " d"
Case " ." : morsCodF = morsCodF + " e"
Case " ..-." : morsCodF = morsCodF + " f"
Case " --." : morsCodF = morsCodF + " g"
Case " ...." : morsCodF = morsCodF + " h"
Case " .." : morsCodF = morsCodF + " i"
Case " .---" : morsCodF = morsCodF + " j"
Case " -.-" : morsCodF = morsCodF + " k"
Case " .-.." : morsCodF = morsCodF + " l"
Case " --" : morsCodF = morsCodF + " m"
Case " -." : morsCodF = morsCodF + " n"
Case " ---" : morsCodF = morsCodF + " o"
Case " .--." : morsCodF = morsCodF + " p"
Case " --.-" : morsCodF = morsCodF + " q"
Case " .-." : morsCodF = morsCodF + " r"
Case " ..." : morsCodF = morsCodF + " s"
Case " -" : morsCodF = morsCodF + " t"
Case " ..-" : morsCodF = morsCodF + " u"
Case " ...-" : morsCodF = morsCodF + " v"
Case " .--" : morsCodF = morsCodF + " w"
Case " -..-" : morsCodF = morsCodF + " x"
Case " -.--" : morsCodF = morsCodF + " y"
Case " --.." : morsCodF = morsCodF + " z"
Case "#" : morsCodF = morsCodF + " "
End Select
Next
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
EE15a()
End Sub
End Class
If you need some letters uppercase, you need provide additional logic (for instance, first letter is always uppercase). The following code creates dictionary with codes and their letters, parses Morse code string with Regex, extracting codes one-by-one and fetching letters based on these codes. I have created two versions - with Regex and Split.
Dim morse = New Dictionary(Of String, String) From
{
{".-", "a"},
{"-...", "b"},
{"-.-.", "c"},
{".", "e"},
{"....", "h"},
{".-..", "l"},
{"---", "o"},
{"#", " "}
}
Dim s = "..../ ./ .-../ .-../ ---/"
'// 1. REGEX
'// Search for '.', '-' and '#' in any combinations followed by '/'
Dim mc = Regex.Matches(s, "[\.\-#]+(?=/)")
'// Fetch each code from dictionary and concatenate them
Dim x = String.Join("", mc.Cast(Of Match).Select(Function(m) morse(m.Value)))
'// 2. SPLIT
'// Dim x = String.Join("", s.Split({"/"}, StringSplitOptions.RemoveEmptyEntries).
'// Select(Function(z) morse(z.Replace("/", "").Trim())))
Console.WriteLine(x)
'// Output: hello
I think you will get more feedback of the code if you add default case for the Select Case switch.
Select Case s
Case " .-" : morsCodF = morsCodF + " a"
Case "#" : morsCodF = morsCodF + " "
Case Else : morsCodF = morsCodF + " WRONG! "
End Select
Check does this line oddel = j - oddel works as expected.
Based on the logic you have oddel should be amount of characters after previously found / character. If so, then calculation oddel = j - oddel doesn't look right.
Because you updating i with current j calculation should be oddel = j - (i -1)
Check For loop.
Because i updated every time with current value of j, code will make one extra loop which will produce "wrong" value.
Other suggestions.
Decoding morse code to the text is simple mapping from one string to another.
In vb.net Dictionary(Of String, String) could be good tool for this.
Do you really need / character? Instead you can use simple space as letter delimeter.
Function FromMorse(code As String) As String
Const DELIMETER As Char = " "c
Static Secret As New Dictionary(Of String, String) From
{
{".-", "a"},
{"-...", "b"},
{"-.-.", "c"},
{"-..", "d"},
{".", "e"},
{"..-.", "f"},
{"--.", "g"},
{"....", "h"},
{"..", "i"},
{".---", "j"},
{"-.-", "k"},
{".-..", "l"},
{"--", "m"},
{"-.", "n"},
{"---", "o"},
{".--.", "p"},
{"--.-", "q"},
{".-.", "r"},
{"...", "s"},
{"-", "t"},
{"..-", "u"},
{"...-", "v"},
{".--", "w"},
{"-..-", "x"},
{"-.--", "y"},
{"--..", "z"},
{"#", " "}
}
Return code.Split(DELIMETER).
Select(Function(c) Secret(c)).
Aggregate(New StringBuilder(), Function(b, c) b.Append(c)).
ToString()
End Function
Usage
Dim code = ".... . .-.. .-.. --- # .-- --- .-. .-.. -.."
Dim decoded = FromMorse(code)
Console.WriteLine(decoded) ' => "hello world"
A Dictionary for fast look-up, String.Split for brevity and a StringBuilder to keep from creating new strings on every iteration.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim s As String = GetTextFromMorse("..../ ./ .-../ .-../ ---/")
Debug.Print(s)
End Sub
Private DictCode As New Dictionary(Of String, String) From
{
{".-", "a"},
{"-...", "b"},
{"-.-.", "c"},
{"-..", "d"},
{".", "e"},
{"..-.", "f"},
{"--.", "g"},
{"....", "h"},
{"..", "i"},
{".---", "j"},
{"-.-", "k"},
{".-..", "l"},
{"--", "m"},
{"-.", "n"},
{"---", "o"},
{".--.", "p"},
{"--.-", "q"},
{".-.", "r"},
{"...", "s"},
{"-", "t"},
{"..-", "u"},
{"...-", "v"},
{".--", "w"},
{"-..-", "x"},
{"-.--", "y"},
{"--..", "z"},
{"#", " "}
}
Private Function GetTextFromMorse(input As String) As String
Dim strArray() As String = input.Split({"/"}, StringSplitOptions.RemoveEmptyEntries)
Dim sb As New StringBuilder
For Each s In strArray
sb.Append(DictCode(s.Trim))
Next
Return sb.ToString
End Function
I have a dataset that is with arround 30000records, so loping inside it and building the string fileStavki trows exeption, systemoutofmemmory. How can i solve this. Is working with arrays possible solution or something else?
Dim sb As New StringBuilder
For Each inRow In ds_in.Tables(0).Rows
rbr += 1
pisi_red = "2" & Enc3.prefill(rbr, "0", 6) & Share.RightPrefill(inRow("prioritet"), "0", 5)
pisi_red &= Enc3.prefill(Enc3.IsNull(inRow("smetka_davac"), "0"), "0", 15)
pisi_red &= Share.RightPrefill(Enc3.lat2kir(Enc3.IsNull(inRow("naziv_davac"), "")), " ", 70)
pisi_red &= Share.RightPrefill(Enc3.IsNull(inRow("povik_broj_davac"), ""), " ", 24)
pisi_red &= Share.RightPrefill(Enc3.lat2kir(Enc3.IsNull(inRow("cel_na_doznaka"), "")), " ", 70)
pisi_red &= Enc3.prefill(inRow("sif_tip_plakanje"), "0", 6)
pisi_red &= "+" & Enc3.prefill(FormatNumber(inRow("iznos"), 5, TriState.False, TriState.False, TriState.False), "0", 21)
pisi_red &= inRow("smetka_primac") & Share.RightPrefill(Enc3.lat2kir(Trim(inRow("naziv_primac"))), " ", 70)
pisi_red &= Share.RightPrefill(Enc3.IsNull(inRow("povik_broj_primac"), ""), " ", 24)
pisi_red &= inRow("tip_instrument") & Share.RightPrefill(Enc3.IsNull(inRow("broj_transakcija"), ""), " ", 16)
pisi_red &= inRow("sistem_poravnuva") & Enc3.prefill(Enc3.IsNull(inRow("edb"), ""), "0", 13)
pisi_red &= vbCrLf
sb.Append(pisi_red)
'fileStavki &= pisi_red
Next
after this i have
sw.Write(fileStavki)
sw.Flush()
sw.Close()
I think even if i use stringbuilder the string fileStavki will be build like this
filestavki = sb.ToString
And here i will also get outofmemory exeption
I redid the search code and wrote it as a vba code instead of a query, but now I am running into errors now that it is all setup. The code is below:
The code I am getting is OBJECT REQUIRED 424 and it is highlighting the
If Me!txtEmpID Is Not Null Then
Private Sub cmdSearch2_Click()
Dim strSQL As String
strSQL = ""
If Me!txtEmpID Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[EmployeeID] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!txtEmpName Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[EmployeeName] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboEEOC Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[EEOC] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboGender Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Gender] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!txtDivision Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Division] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboRR Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Region] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboDD Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[District] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboJobGroupCode Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[JobGroupCOde] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!txtCenter Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Center] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!txtJobD Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[JobDesc] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboJobGroup Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[JobGroup] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboFunction Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Function1] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboMtgReadyLvl Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[MeetingReadinessRating] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboMgrReadyLvl Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[ManagerReadinessRating] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!txtFeedback Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[EmployeeFeedback] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboDevelopment1 Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"([DevelopmentForEmployee1] LIKE '*" & Me!Me!cboDevelopment1 & " * ' " & _
"OR [DevelopmentForEmployee2] LIKE '*" & Me!Me!cboDevelopment1 & " * ' " & _
"OR [DevelopmentForEmployee3] LIKE '*" & Me!Me!cboDevelopment1 & " * ' " & _
"OR [DevelopmentForEmployee4] LIKE '*" & Me!Me!cboDevelopment1 & " * ' " & _
"OR [DevelopmentForEmployee5] LIKE '*" & Me!Me!cboDevelopment1 & " * ') "
End If
If Me!cboDevelopment2 Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"([DevelopmentForEmployee1] LIKE '*" & Me!Me!cboDevelopment2 & " * ' " & _
"OR [DevelopmentForEmployee2] LIKE '*" & Me!Me!cboDevelopment2 & " * ' " & _
"OR [DevelopmentForEmployee3] LIKE '*" & Me!Me!cboDevelopment2 & " * ' " & _
"OR [DevelopmentForEmployee4] LIKE '*" & Me!Me!cboDevelopment2 & " * ' " & _
"OR [DevelopmentForEmployee5] LIKE '*" & Me!Me!cboDevelopment2 & " * ') "
End If
If Me!cboDevelopment3 Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"([DevelopmentForEmployee1] LIKE '*" & Me!Me!cboDevelopment3 & " * ' " & _
"OR [DevelopmentForEmployee2] LIKE '*" & Me!Me!cboDevelopment3 & " * ' " & _
"OR [DevelopmentForEmployee3] LIKE '*" & Me!Me!cboDevelopment3 & " * ' " & _
"OR [DevelopmentForEmployee4] LIKE '*" & Me!Me!cboDevelopment3 & " * ' " & _
"OR [DevelopmentForEmployee5] LIKE '*" & Me!Me!cboDevelopment3 & " * ') "
End If
If Me!cboDevelopment4 Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"([DevelopmentForEmployee1] LIKE '*" & Me!Me!cboDevelopment4 & " * ' " & _
"OR [DevelopmentForEmployee2] LIKE '*" & Me!Me!cboDevelopment4 & " * ' " & _
"OR [DevelopmentForEmployee3] LIKE '*" & Me!Me!cboDevelopment4 & " * ' " & _
"OR [DevelopmentForEmployee4] LIKE '*" & Me!Me!cboDevelopment4 & " * ' " & _
"OR [DevelopmentForEmployee5] LIKE '*" & Me!Me!cboDevelopment4 & " * ') "
End If
If Me!cboDevelopment5 Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"([DevelopmentForEmployee1] LIKE '*" & Me!Me!cboDevelopment5 & " * ' " & _
"OR [DevelopmentForEmployee2] LIKE '*" & Me!Me!cboDevelopment5 & " * ' " & _
"OR [DevelopmentForEmployee3] LIKE '*" & Me!Me!cboDevelopment5 & " * ' " & _
"OR [DevelopmentForEmployee4] LIKE '*" & Me!Me!cboDevelopment5 & " * ' " & _
"OR [DevelopmentForEmployee5] LIKE '*" & Me!Me!cboDevelopment5 & " * ') "
End If
If Me!txtJustification Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Justification] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!txtNotes Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Notes] LIKE '*" & Me!txtEmpID & " * ' "
End If
If Me!cboChanged Is Not Null Then
strSQL = strSQL & IIf(strSQL = "", "", " AND ") & _
"[Changed] LIKE '*" & Me!txtEmpID & " * ' "
End If
strSQL = "SELECT * FROM [CDData] WHERE " & strSQL
DoCmd.RunSQL strSQL
End Sub
Checking for null in If statements is a little different:
If Not IsNull(Me!txtEmpID) Then
And so on.