Verilog: if statement unexpected behavior - if-statement

I am implementing the MIPS data path (behavioral) in Verilog and the when I simulate my code, the behavior is unexpected.
Here the case of BEQ and BNE (branch if equal/not equal) instructions is shown. ALU_Out determines whether the two registers are equal or not. Non of these really matter cause my problem is basically how verily skips my condition. So, I from the signals in waveform, ALU_out is zero, yet whatever happens inside the if (ALU_Out == 32'd1) is executed once. such that My PC becomes PC+6. now if my ALU_Out actually equals 1, the PC becomes PC+6+6 (It's 1 ==> becomes 13) I have also integrated some kinna flags inside this if statement and made sure it executes once.
Even when I added else to this if, my flags clearly indicated that the if had been executed once before else.
The very same thing occurs in the case of BNE and desired condition is checked after the if statement is executed once.
Would you tell me what is wrong with this code.
Many thanks in advance.
if (ALU_op == 6'd30) //BEQ
begin
ALU_out = ((ALU_in1) == (ALU_in2));
if (ALU_out == 32'd1)
begin
PC = PC + Imm_32;
end
end
if (ALU_op == 6'd31) //BNE
begin
ALU_out = ((ALU_in1) == (ALU_in2));
if (ALU_out == 0)
begin
PC = PC + Imm_32;
end
end
a screen shot of my waveform
UPDATE: still haven't done anything about the non-blocking assignment, But i did modify the way I update PC by adding a next_PC to my code.the If statement problem is gone. Still, the problem is when a jump or branch occurs, the next PC is calculated properly but the instruction at the branch target won't be fetched the same clock!
please look at this photo
and this is supposed to be a single-cycle MIPS processor so that an instruction should be fetched and executed at one cycle. that's why the delay caused by non-blocking assignment is not desired!
always #(*)
begin
IR <= Instruction;
end
always #(posedge clk)
begin
PC = next_PC;
OverFlow = 0;
end
// Decode + Operand Fetch //
always # (IR)
begin
Op_code = IR[31:26];
if (Op_code == 6'd0) //R-type Instructions
begin
Func = IR[5:0];
if (Func == 6'b100000) //ADD
begin
ALU_op = 6'd1; //as numbered in LAB manual
read_addr1 = IR [25:21]; //Rs
read_addr2 = IR [20:16]; //Rt
end //end of ADD
if (Func == 6'b100001) //ADDU
begin
ALU_op = 6'd2; //as numbered in LAB manual
read_addr1 = IR [25:21]; //Rs
read_addr2 = IR [20:16]; //Rt
end //end of ADDU
/* some code here skipped to make the code shorter*/
if (Op_code == 6'b000100) //BEQ (Branch if Equal)
begin
ALU_op = 6'd30; //as numbered in LAB manual
read_addr1 = IR [25:21]; //Rs
read_addr2 = IR [20:16]; //Rt
Imm_32 = {{16{IR[15]}},IR [15:0]}; //Offset 2nd operand: imm-32 (Sign Extended Imm_16)
//BT = PC + Imm_32;
end
if (Op_code == 6'b000101) //BNE (Branch if NOT Equal)
begin
ALU_op = 6'd31; //as numbered in LAB manual
read_addr1 = IR [25:21]; //Rs
read_addr2 = IR [20:16]; //Rt
Imm_32 = {{16{IR[15]}},IR [15:0]}; //Offset 2nd operand: imm-32 (Sign Extended Imm_16)
end
if (Op_code == 6'b000001)
begin
if ( IR [20:16] == 5'b00001) //BGEZ (Branch on Greater than or Equal to Zero)
begin
ALU_op = 6'd33; //as numbered in LAB manual
read_addr1 = IR [25:21]; //Rs
Imm_32 = {{16{IR[15]}},IR [15:0]}; //Offset 2nd operand: imm-32 (Sign Extended Imm_16)
end
if (IR [20:16] == 5'b10000) //BLTZAL (Branch on less than Zero And Link)
begin
ALU_op = 6'd34; //as numbered in LAB manual
read_addr1 = IR [25:21]; //Rs
Imm_32 = {{16{IR[15]}},IR [15:0]}; //Offset 2nd operand: imm-32 (Sign Extended Imm_16)
end
end
if (Op_code == 6'b000010) //J (Jump)
begin
ALU_op = 6'd35; //as numbered in LAB manual
Imm_32 = {PC [31:26],IR [25:0]}; //Jump Address
end
if (Op_code == 6'b000011) //JAL (Jump And Link)
begin
ALU_op = 6'd36; //as numbered in LAB manual
Imm_32 = {PC [31:26],IR [25:0]}; //Jump Address
end
end // end of DECODE
// Execution & Write Back//
always # (ALU_op, ALU_in1, ALU_in2)
begin
next_PC = PC+1;
wr_En = 0;
DM_wrEn_0 = 0;
DM_wrEn_1 = 0;
DM_wrEn_2 = 0;
DM_wrEn_3 = 0;
if (ALU_op == 6'd1) //ADD
begin
ALU_out = ALU_in1 + ALU_in2;
write_addr = IR [15:11]; //Rd
if( ( (ALU_in1[31]) && (ALU_in2[31]) && (!ALU_out[31]) )||( (!ALU_in1[31]) && (!ALU_in2[31]) && (ALU_out[31]) ) )
OverFlow = 1'b1;
wr_En = 1;
write_data = ALU_out;
end
if (ALU_op == 6'd2) //ADDU
begin
ALU_out = ALU_in1 + ALU_in2;
write_addr = IR [15:11]; //Rd
wr_En = 1;
write_data = ALU_out;
end
/* some code here skipped to make it shorter*/
if (ALU_op == 6'd30) //BEQ
begin
ALU_out = ((ALU_in1) == (ALU_in2));
if (ALU_out == 32'd1)
begin
//PC = PC + Imm_32;
next_PC = PC + Imm_32;
BT = 32'd56;
//PC = BT;
end
end
if (ALU_op == 6'd31) //BNE
begin
ALU_out = ((ALU_in1) == (ALU_in2));
if (ALU_out == 0)
begin
//PC = PC + Imm_32;
next_PC = PC + Imm_32;
BT = 32'd90;
end
end
if (ALU_op == 6'd33) //BGZE
begin
ALU_out = ((ALU_in1) >= 0);
if (ALU_out)
begin
//PC = PC + Imm_32;
next_PC = PC + Imm_32;
end
end
if (ALU_op == 6'd34) //BLTZAL
begin
ALU_out = ((ALU_in1) < 0);
if (ALU_out)
begin
write_addr = 5'd31; //$ra ($31)
write_data = PC;
wr_En = 1;
//PC = PC + Imm_32;
next_PC = PC + Imm_32;
end
end
if (ALU_op == 6'd32) //JR
begin
//PC = ALU_in1;
next_PC = ALU_in1;
end
if (ALU_op == 6'd35) //J
begin
//PC = Imm_32;
next_PC = Imm_32;
end
if (ALU_op == 6'd36) //JAL
begin
write_addr = 5'd31; //$ra
wr_En = 1;
write_data = PC;
//PC = Imm_32;
next_PC = Imm_32;
end
end //end of EXE and WB always block

Now that we know you want it to be single cycle, that clarifies alot.
First, youll need to decide were youre registers are for talking to the memory, are you putting the address to access the instruction memory in a register or the resulting instructions because right now with your always #(*) IR <= Instruction; end and always #(posedge clk) begin PC = nextPC end, youre doing a weird combination of both. You need to do either:
always #(posedge clk) begin
IR <= Instruction;
PC <= nextPC;
end
And address the instruction memory with nextPC or:
always #(posedge clk) begin
PC <= nextPC;
end
assign IR = Instruction;
And address the instruction memory with PC. Note that Morgan's comment the reading from memory should take a cycle is generally correct, however, we will assume you have some kind of combinationally-read memory that does not need a latched address and output/input. In real systems, you really should be prepared to have registers on address and input/output bus to memory though.
A few other stylistic notes:
Its best not to write your own sensitivity lists, use always #(*), not always #(IR) for combinational logic (using always #(posedge clk) for sequential logic.
Use blocking assign (=) in always #(*) (combinational) blocks and NBA (<=) in always #(posedge clk) (sequential) blocks.
Use case statements rather than a long list of if .. if .. if .. for decoding opcodes. Its much easier to read
I suggest replacing the opcodes with parameters or macros so the code reads easier (like instead of if (op == 6'b001001), you get parameter ALU_ADD = 6'b001001; ... if (op == ALU_ADD), its much clearer; even better in a case stamement case (op) ALU_ADD: ... ALU_SUB: ... ALU_OR: ... endcase)

Related

VHDL 3-8 decoder using if else syntax error near 'else' and 'process'

I've been trying to compile this program and tried to make edits according to my understanding of the error message that increased the amount of errors. This is the 2nd VHDL code I've ever written and I'm not sure what more I can do
this is the code:
entity maashro3o is
port (Q: out bit_vector (0 to 7);
A: in bit_vector(2 down to 0);
en: in bit);
end maashro3o;
architecture maashro3o of maashro3o is
begin
process(A, en)
begin
if (en = "1")
then
if (A = "000")
then
Q <= "10000000";
else if (A = "001") then
Q <= "01000000";
else if (A = "010") then
Q <= "00100000";
else if (A = "011") then
Q <= "00010000";
else if (A = "100") then
Q <= "00001000";
else if (A = "101") then
Q <= "00000100";
else if (A = "110") then
Q <= "00000010";
else if (A = "111") then
Q <= "00000001";
END If;
else
Q <= "00000000";
End If;
end process;
end maashro3o
Update
I changed else if to elsif and else respectively.
I tried to remove then from else but I'm getting similar errors
entity maashro3o is
port (Q: out bit_vector (0 to 7);
A: in bit_vector(2 downto 0);
en: in bit);
end maashro3o;
architecture maashro3o of maashro3o is
begin
process(A, en)
begin
if (en = '1')
then
if (A = "000")
then
Q <= "10000000";
elsif (A = "001") then
Q <= "01000000";
else (A = "010") then
Q <= "00100000";
elsif (A = "011") then
Q <= "00010000";
else (A = "100") then
Q <= "00001000";
elsif (A = "101") then
Q <= "00000100";
else (A = "110") then
Q <= "00000010";
elsif(A = "111") then
Q <= "00000001";
END If;
else
Q <= "00000000";
End If;
end process;
end maashro3o;
You need to change all the elses inside the block begins with
if (A="000") then
.
.
.
end if;
There is no "else if" keyword in VHDL. Use "elsif". When coding an if-else statement with multiple conditions, you should not write else after elsif or vice versa. You can not use them both.
"else" keyword does not declare a specific statement. It is used for checking only one condition and doing something when condition is not satisfied.
Also when writing a VHDL code, don't forget to include the libraries you will need and may be need.
Corrected code is given below.
library ieee;
use ieee.std_logic_1164.all;
entity maashro3o is
port (Q: out bit_vector (0 to 7);
A: in bit_vector(2 downto 0);
en: in bit);
end maashro3o;
architecture maashro3o of maashro3o is
begin
process(A, en)
begin
if (en = '1') then
if (A = "000") then
Q <= "10000000";
elsif (A = "001") then
Q <= "01000000";
elsif (A = "010") then
Q <= "00100000";
elsif (A = "011") then
Q <= "00010000";
elsif (A = "100") then
Q <= "00001000";
elsif (A = "101") then
Q <= "00000100";
elsif (A = "110") then
Q <= "00000010";
elsif(A = "111") then
Q <= "00000001";
end if;
else
Q <= "00000000";
end if;
end process;
end maashro3o;
Why do you want to use if else statements only, since decoder is a combinational logic you can use case statement to design the logic, it will be more appropriate.

VHDL coding error "Else clause after check for clock not supported"

I'm trying to make a counter that sends out a carry signal after every 64 clock pulses. When I try to synthesize the code shown below, (in Vivado) I get the following error,
Else clause after check for clock not supported.
(On the line signaled with the '!!')
I did something very similar in a different project and I did not get any error there, so I don't really get what's wrong. Any help?
entity refresh_counter is
port( CLK : in STD_LOGIC;
CLR : in STD_LOGIC;
CARRY : out STD_LOGIC);
end refresh_counter;
architecture Behavioral of refresh_counter is
begin
process(CLK)
variable tel : integer;
begin
if (CLK'event and CLK = '1') then
if CLR = '1' then
tel := 0;
end if;
else
if (tel < 63) then !!
tel := tel + 1;
else
CARRY <= '1';
tel := 0;
end if;
end if;
end process;
end Behavioral;
As mentioned by #scary_jeff in the comments section, your else doesn't make sense as you cannot practically implement not at rising edge. Here is an implementation that will do the job.
The process has two variables n_carry and n_tel. You can treat them like the combinational output of the FSM. On the clock's rising edge, these two variables are transferred to carry and tel respectively.
In the case CLR is high, 0 will be transferred instead.
The n_carry and n_tel logic is implemented combinationally in hardware. It takes tel as an input and the decision making has been coded in the if-elsif-else sequence in the process.
library std;
library ieee;
use ieee.std_logic_1164.all;
entity refresh_counter is
port( CLK : in STD_LOGIC;
CLR : in STD_LOGIC;
CARRY : out STD_LOGIC);
end refresh_counter;
architecture Behavioral of refresh_counter is
signal tel: integer := 0;
begin
process(CLK, CLR, tel)
variable n_tel: integer := 0;
variable n_carry: STD_LOGIC := '0';
begin
if (tel < 63) then
n_carry := '0';
n_tel := tel + 1;
elsif (tel = 63) then
n_carry := '1';
n_tel := 0;
else
-- This case should never arise in practice
n_carry := '0';
n_tel := 0;
end if;
if (CLK'event and CLK = '1') then
if CLR = '1' then
tel <= 0;
CARRY <= '0';
else
tel <= n_tel;
CARRY <= n_carry;
end if;
end if;
end process;
end Behavioral;

Informix 9.52C1 - replace carriage return and line feed

I search google and couldn't find anything that really helped me IBM website show Informix 11.5 and up functions, like if they have stop supporting 9.52C1 or something. Hence the reason I am here.
As the topic stated I'm using Informix 9.52C1. I got this information using the SQL:
SELECT owner FROM systables WHERE TABNAME= ' VERSION';
I'm not sure if the replace function is even supported because when I execute the statement:
SELECT col1, REPLACE('r','p','poster') as col2 FROM table;
The column col2 contains just the letter 'r' however no error was thrown although I used the REPLACE() function.
I know the escape characters (CRLF) can be found using the "\r\n" escape format because this SQL worked accordingly:
SELECT * FROM table WHERE col1 LIKE '%\r\n%';
Note: I used the above SQL to retrieve the version number as I only had access via a client DB application. If however you have access to the actual host running the informix DB server I'm sure there is some command arguement to resolve the version maybe the defualt linux --version or -v arguement with the db server application.
And this indeed returned only the records that contained CRLF.
My main job is to place a backslash in front of CR and LF as I am migrating data from Informix 9.52C1 to a PostgreSQL database. I'm planning to use the COPY function to load the data to the PostgreSQL database and the COPY function works in this manner as I have done a test record. My dilemma is extracting the data from Informix in the correct format. Can anyone assist with this issue?
I have tried:
SELECT REPLACE('\\\r\\\n','\r\n',col1) as description FROM table;
However this didn't work I believe due to the replace function, as I have mention I am not sure if the replace function is available in this Informix version.
Thanks in advance,
jerg
P.S. None of the functions ASCII(),CHAR() and CHR() worked either. Some sites suggested these function. But as far as I can see the functions CHR() & ASCII() was implemented in verison 11.5+. This post suggested the functions.
To migrate data between databases you can use JDBC drivers (I use Jython, but Java or other language which can use JDBC driver will be ok) and then SELECT ... from source database (Informix) and INSERT ... just read data into destination (PostgreSQL). With BatchInsert or PreparedStatement it is really fast. In my code it looks like:
insert_str = 'INSERT INTO ' + table_name + ' (' + column_names + ') VALUES (' + question_marks + ')'
insert_stmt = db_to.prepareStatement(insert_str)
...
pstm2 = db_from.createStatement()
rs_in = pstm2.executeQuery('SELECT %s FROM %s %s' % (column_names, table_name, order_str))
...
while (rs_in.next()):
for i in range(1, col_count + 1):
insert_stmt.setObject(i, rs_in.getObject(i))
Of course you must take care of errors, auto commit, fetch size etc. but I think it is worth your effort.
Your idea with COPY ... is also good. Do you save output from Informix in text file? If it is in text file you can simply correct text file before importing it to PostgreSQL.
I don't recognize the version 9.52C1. An Informix version might be 9.52.UC1 — with a choice from U, F, W, H, T for the first letter. But then again, the main version numbers were 9.00..9.03, 9.10..9.16, 9.20, 9.21, 9.30, 9.40, 10.00, 11.10, 11.50, 11.70, 12.10 — a sequence which doesn't include a 9 and a 5 in a single version. Well, in many ways, it doesn't matter; any version 9.x has been out of support for most of a decade, if not longer, and shouldn't still be in use.
Assuming that an upgrade to a modern version of Informix is not in the cards, you are stuck with implementing your own functions. To do the job, you'd do best to implement them in C and install them as a package of UDRs (user-defined routines) in a shared library. That would give you the best performance. Assuming that's not feasible (I don't have a set of such functions on hand, but it shouldn't be hard to write them), then you have to fall back on SPL (stored procedure language) routines. These are not fast because of the limitations of SPL w.r.t substring operations — specifically, the built-in substring operations with [] notation do not accept variables as subscripts. That's really painful, to be polite about it.
Here's a version of char_at which fetches a single character at a given position in a string of up to 255 characters:
-- #(#)$Id: char_at.spl,v 1.1 1999/05/17 23:59:59 jleffler Exp $
--
-- CHAR_AT stored procedure, to return character at given position in string
--
-- Author: J Leffler
-- Date: 1999-05-17
CREATE PROCEDURE char_at(str VARCHAR(255), pos SMALLINT) RETURNING CHAR(1);
DEFINE c CHAR(1);
IF pos > LENGTH(str) OR pos <= 0 THEN
LET c = NULL;
ELIF pos <= 16 THEN
IF pos = 1 THEN LET c = str[ 1];
ELIF pos = 2 THEN LET c = str[ 2];
ELIF pos = 3 THEN LET c = str[ 3];
ELIF pos = 4 THEN LET c = str[ 4];
ELIF pos = 5 THEN LET c = str[ 5];
ELIF pos = 6 THEN LET c = str[ 6];
ELIF pos = 7 THEN LET c = str[ 7];
ELIF pos = 8 THEN LET c = str[ 8];
ELIF pos = 9 THEN LET c = str[ 9];
ELIF pos = 10 THEN LET c = str[10];
ELIF pos = 11 THEN LET c = str[11];
ELIF pos = 12 THEN LET c = str[12];
ELIF pos = 13 THEN LET c = str[13];
ELIF pos = 14 THEN LET c = str[14];
ELIF pos = 15 THEN LET c = str[15];
ELIF pos = 16 THEN LET c = str[16];
END IF;
ELIF pos <= 32 THEN LET c = char_at(str[ 17, 32], pos - 1 * 16);
ELIF pos <= 48 THEN LET c = char_at(str[ 33, 48], pos - 2 * 16);
ELIF pos <= 64 THEN LET c = char_at(str[ 49, 64], pos - 3 * 16);
ELIF pos <= 80 THEN LET c = char_at(str[ 65, 80], pos - 4 * 16);
ELIF pos <= 96 THEN LET c = char_at(str[ 81, 96], pos - 5 * 16);
ELIF pos <= 112 THEN LET c = char_at(str[ 97,112], pos - 6 * 16);
ELIF pos <= 128 THEN LET c = char_at(str[113,128], pos - 7 * 16);
ELIF pos <= 144 THEN LET c = char_at(str[129,144], pos - 8 * 16);
ELIF pos <= 160 THEN LET c = char_at(str[145,160], pos - 9 * 16);
ELIF pos <= 176 THEN LET c = char_at(str[161,176], pos - 10 * 16);
ELIF pos <= 192 THEN LET c = char_at(str[177,192], pos - 11 * 16);
ELIF pos <= 208 THEN LET c = char_at(str[193,208], pos - 12 * 16);
ELIF pos <= 224 THEN LET c = char_at(str[209,224], pos - 13 * 16);
ELIF pos <= 240 THEN LET c = char_at(str[225,240], pos - 14 * 16);
ELIF pos <= 255 THEN LET c = char_at(str[241,255], pos - 15 * 16); -- Note asymmetry in upper bound!
ELSE LET c = NULL; -- Not reached!
END IF;
RETURN c;
END PROCEDURE;
Handling general substrings and the like is similarly painful. I've never gone to the effort of building even a semi-performant SPL implementation of SUBSTR. It is far, far better to upgrade to a version of Informix that has the support built-in.
CHR() and ASCII()
The CHR(). ASCII() functions can be simulated with:
-- #(#)$Id: chr.sql,v 1.2 2008/09/19 18:48:37 jleffler Exp $
--
-- #(#)Procedure CHR() - return character corresponding to integer
CREATE PROCEDURE chr(i INTEGER) RETURNING CHAR(1) AS result;
DEFINE c CHAR;
IF i < 0 OR i > 255 THEN
RAISE EXCEPTION -746, 0, 'CHR(): integer value out of range 0..255';
END IF;
IF i = 0 OR i IS NULL THEN
LET c = NULL;
ELSE
SELECT chr INTO c FROM ascii WHERE val = i;
END IF;
RETURN c;
END PROCEDURE;
-- #(#)$Id: ascii.sql,v 1.2 2008/09/19 18:40:19 jleffler Exp $
--
-- Procedure ASCII - returning integer corresponding to character.
-- Misnomer: it works on any single-byte character.
CREATE PROCEDURE jl_ascii(C CHAR) RETURNING INT AS result;
DEFINE i INTEGER;
IF c IS NULL THEN
LET i = 0;
ELSE
SELECT val INTO i FROM ascii WHERE chr = c;
END IF;
RETURN i;
END PROCEDURE;
which requires a table:
-- #(#)$Id: asciitbl.sql,v 1.2 2005/03/30 17:51:12 jleffler Exp $
--
-- #(#)Create ASCII Table (for ASCII and CHR functions).
CREATE TABLE ascii
(
val INTEGER NOT NULL UNIQUE CONSTRAINT u1_ascii,
chr CHAR(1) NOT NULL UNIQUE CONSTRAINT u2_ascii
);
REVOKE ALL ON ascii FROM PUBLIC;
GRANT SELECT ON ascii TO PUBLIC;
and the data to go in it — 255 lines such as:
…
32|
33|!
34|"
35|#
36|$
37|%
38|&
39|'
40|(
…
64|#
65|A
66|B
67|C
68|D
69|E
…
You should be able to find a copy of this code at the IIUG under the name ascii.

If statement conditions not met, code still executing

I'm writing a VBScript that searches the Active Directory for a computer object. If the object does not exist or exists and is in the correct OU, then it should run a separate script that creates/joins the computer to the AD.
ObjExist_CorrectOU_7 = Null
ObjExist_CorrectOU_10 = Null
If compare = True Then
Win7_OU = "OU=DisallowRDP,OU=64Bit,OU=Win8"
Win10_OU = "OU=DisallowRDP,OU=64Bit,OU=Win10"
For x = 16 To 46
If Asc(Mid(objRS.Fields("distinguishedName"), x, 1)) = Asc(Mid(Win7_OU, (x - 15), 1)) Then
ObjExist_CorrectOU_7 = True
Else
ObjExist_CorrectOU_7 = False
End If
Next
For y = 16 To 46
If Asc(Mid(objRS.Fields("distinguishedName"), y, 1)) = Asc(Mid(Win10_OU, (y - 15), 1)) Then
ObjExist_CorrectOU_10 = True
Else
ObjExist_CorrectOU_10 = False
End If
Next
End If
If ObjExist_CorrectOU_7 = True Then
WScript.Echo "TRUE"
End If
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
filename = "C:\programdata\dell\kace\k2000_deployment_info.conf"
Win7_Deployment = "deployment_name=Windows 7 x64 with SP1, join AD"
Win10_Deployment = "deployment_name=Development Windows 10 (x64), join AD"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename)
Do While Not f.AtEndOfStream
If ((f.ReadLine = Win7_Deployment) Or ((f.ReadLine = Win7_Deployment) And (ObjExist_CorrectOU_7 = True))) Then
WScript.Echo "IT WORKED!"
'objShell.Run "JoinAD_Win7.vbs"
Exit Do
End If
On Error Resume Next
Loop
f.Close
Set g = fso.OpenTextFile(filename)
Do While Not f.AtEndOfStream
If ((g.ReadLine = Win10_Deployment) Or ((g.ReadLine = Win10_Deployment) And (ObjExist_CorrectOU_10 = True))) Then
'objShell.Run "JoinAD_Win10.vbs"
WScript.Echo "IT WORKED AGAIN!"
Exit Do
End If
On Error Resume Next
Loop
g.Close
Set objShell = Nothing
The problem I'm running into is that the two If..Then statements execute every time, even though I know the conditions are absolutely NOT being met.
Does it have to do with my use of Or and And?
Your question does not satisfy Minimal, Complete, and Verifiable example criteria. However, at first sight: read On Error Statement and ReadLine Method and Working with Files documentation.
Do While Not f.AtEndOfStream
''' ↓ this `ReadLine` reads every uneven line i.e. the 1st, 3rd, 5th, …
If ((f.ReadLine = Win7_Deployment) Or ((f.ReadLine = Win7_Deployment) And (ObjExist_CorrectOU_7 = True))) Then
''' this one reads every even line ↑ i.e. the 2nd, 4th, 6th, …
WScript.Echo "IT WORKED!"
'objShell.Run "JoinAD_Win7.vbs"
Exit Do
End If
On Error Resume Next ' this causes that script continues on line next to IF … THEN
' in case of uneven records in file.
' i.e. runtimme error "Input past end of file"
Loop
Use something like
Do While Not f.AtEndOfStream
sReadLine = f.ReadLine
If ((sReadLine = Win7_Deployment) Or ((sReadLine = Win7_Deployment) And (ObjExist_CorrectOU_7 = True))) Then
WScript.Echo "IT WORKED!"
'objShell.Run "JoinAD_Win7.vbs"
Exit Do
End If
''' get rid of `On Error Resume Next` statement at all
Loop
And what about Do While Not f.AtEndOfStream followed up by g.ReadLine? Use either f or g (the same TextStream object in both)…

Matching enclosing characters Python

So I am trying to split characters a certain way.
If I provide this string:
text (text (adsf (asdfasdfjkl) asdfjlkasdjf) stuff) (morestuff stuff)
I want it to split it into:
['text', '(text (adsf (asdfasdfjkl) asdfjlkasdjf) stuff)', '(morestuff stuff)']
Code I had:
def pair_char(left, right, start, text, exclusive=False, verbose=False):
package = []
for e, c in enumerate(text):
left_c = right_c = 0
if text[e] == left:
left_c += 1
marker = start = e
while text[marker+1] != right or left_c > right_c:
marker += 1
if verbose:
print left_c, right_c, text[marker], left, right, text[marker]==left, text[marker]==right
if marker+1 >= len(text):
break
if text[marker] == left_c:
print "left_c"
left_c += 1
if text[marker] == right_c:
print "right_c"
right_c += 1
end = marker
if exclusive:
package.append(text[start+1:end])
else:
package.append(text[start:end+1])
e = end
package = "".join(package)
return package
Any suggestions?