Everything for Electronics

Tech Forum





PCB Chem Disposal Answered March 2015

I’m interested in photo etching copper-clad PCBs. Most guides don't say what to do with the chemicals when I'm done. Do I just pour them down the drain or will it hurt the environment (or my pipes?).

#3153
Gerardo Rios
Phoenix, AZ



Answers

If you etch copper off a copper-clad PCB, you sure don't want to port etchant into copper pipes! And you don't want the copper ions from the etched board going into the waste-water system. After all, we all live downstream of someone else. MG Chemicals offers two disposal ideas, which you can read here. www.mgchemicals.com/tech-support/ferric_faq/.

Jon Titus
Herriman, UT


X10 Cable Build Answered March 2015

I have an early X10 Home Control Timer (Model CP-290) to which I have lost the programming cable. Does anyone know where I can get the pinout so I could fashion my own replacement cable?

#3151
Leigh Guzman
Oxnard, CA



Answers

The CP-290 is very old and was sold in the early 1980s. The communication protocol is RS232 serial


Baud Rate:  600
Data Bits: 8
Parity: None
Stop Bits: 1


The connector on the back is a standard 5-Pin DIN socket. Looking at the back of the unit the pins are 5-4-3-2-1 starting at the left and going counter-clockwise to the right with pin 5 on the left, 3 on the bottom and 1 on the right.


Pin 1 - No Connection
Pin 2 - Receive Data (In)
Pin 3 - Ground
Pin 4 - Transmit Data (Out)
Pin 5 - No Connection


To plug into a computer like an IBM compatible these connections would go to a 9-Pin female serial connector:


CP290 —> DE9
2 RxD —> 3 Txd
3 Gnd —> 5 Gnd
4 TxD —> 2 RxD

Rick Swenton
via email

Attached is a scanned image from the manual.

Pete Cermak
Mokena, Il.

The 5-pin DIN (pins 1-5) — The middle pin (3) is GND, the pins on either side (2 & 4) are Rx & Tx. I don't recall which. You might have to swap them to work. The outer pins are not connected.

Ted Hess
Hudson, MA

From the CP290 programming guide:


Pin 1 - No Connection
Pin 2 - Receive (input)
Pin 3 - Ground
Pin 4 - Transmit (output)
Pin 5 - No connection


Looking at the face of the connector with Pin 1 at the 3 o'clock position and Pin 5 at the 9 o'clock position.

Al Jaszek
Needham, MA


Diode Decision Answered February 2015

Can you PLEASE indicate which germanium diode would best fit this SW radio? Either a 1N34A or 1N60?

#2153
Michael Williams
Crete, IL



Answers

I could give you a lot of technobabble, but the truth is there's no practical difference between 1N34A and 1N60 in this application. Most people get a bag of diodes, preferably from different batches, and check them for the loudest signal with best sound quality.

Craig Hyatt
Salt Lake City, UT

Both diodes — 1N34 and 1N60 —­ are germanium diodes, and both are of similar physical size. The important thing is that this diode family has the smallest forward voltage characteristic, which is important for rectification of small voltages. They both will operate at radio frequencies. The forward current rating and the reverse voltage characteristics are unimportant in this application.


Bottom line: Either one will work in this application. My personal choice would be the 1N60 because the documentation available for this device is superior, with V-I curves to show the typical forward voltage characteristic.

Peter A. Goodwin
Rockport, MA

Either should work well. Both have a conduction knee starting around 0.15 or 0.20 volts. The IN60, being slightly newer, probably has more tightly-controlled specs. One source for diodes and their specifications: http://store.americanmicrosemiconductor.com/1n60.html and http://store.americanmicrosemiconductor.com/1n34a.html. BTW, for better Q of the tuner, connect the diode to a tap on the coil.

B. Bresnik
via email

You can use either type and expect the same results. Both diodes are germanium and both have a forward voltage drop, (often called “turn-on” voltage — where a diode begins conducting), of about 0.3V. A diode with even lower forward voltage is the 1N5817, a Schottky diode, which has a forward voltage of about 0.16 volts. The forward voltage determines how weak a signal can be heard.


The author at the following URL presents a comprehensive table of 1N34 and 1N60 subtypes and a few Schottky diodes used as detectors in crystal radios. If you view it, look in the column labelled Measured Vr. http://wiki.waggy.org/dokuwiki/crystal_radio/detector. However, long before the sensitivity of the diode becomes the limiting factor, four other factors will limit the performance of the radio you propose. Those are:
   Selectivity — only one tuned circuit is used and it is not impedance matched at input or output.
   Antenna length — definitely use more than 10 feet — a goal would be 50 feet and as high as possible.
   Ground losses — connect a wire to Earth or to a large expanse of metal.
   Frequency of operation (also related to selectivity) — with this type of circuit, as you increase frequency, the bandwidth increases. This means it lets through more and more stations at the same time.


If you haven’t had the opportunity to read them, you’ll probably find the insights in the wiki entry on crystal radios time saving. Especially note the sections on tuned circuits, impedance matching, and the problem of selectivity. It can be found at: http://en.wikipedia.org/wiki/Crystal_radio The following URL shows how to connect your tuning circuit and diode directly to your LM386 without the LM741 you have in the middle of the circuit. http://makerf.com/posts/an_lm386_powered_crystal_radio_in_an_altoids_smalls_tin


You specified a number of turns for your coil but I didn’t see any diameter for the it. Starting coil designs would be 56 turns for a 5 inch diameter oatmeal box or 75 turns on a 2 1/8 inch diameter coil, each of which could be used with your 365 pf variable capacitor. 22 to 24 AWG bare enameled wire would work for the 5" diameter. 28 to 30 AWG would work for the 2 1/8" diameter.


To help optimize selectivity, you want what's called a "square coil." This means the coil length is about equal to the diameter. Not critical but helpful. Small diameter wire increases resistance which degrades selectivity. It likely to be less frustrating to first get your design working at the lower AM broadcast band frequencies before pushing up into the shortwave frequencies.


Last, it looks like you might put taps on your coil. The following URL has photos that might give you helpful ideas. Once on the website, click on the “Oatmeal box crystal set.” www.midnightscience.com/download%20files/XSOB1-manual-050108.pdf Please accept my apologies if I've included to much information. Best wishes for your success.

David Tancig
Columbia, SC


IC Identification Answered January 2015

Figure 1 is the front-end of a simple frequency counter, 1 Hz to 1 MHz. I can't seem to find IC1 4583, (I'm guessing this is a CD4583). Pin 4 of IC1 feeds the input of a CD4026. Q1 is a 2N930 and IC5A is a 556.

Part Description Part Description
R1 8.2M TR1 1M trimmer 10T
R2 100K TR2 1K trimmer 10T
R3 470K Q1 2N930 or 2N2222A
R4 470 ohm    
R5-R7 10K IC1 CD4583
R8 3.3M IC2-IC4 CD4026
C1, C2 1µF 63V Mylar NPO IC5 LM556
C3 47µF 16V IC6 CD4007
C4 .1µF 63V IC7 7805
C5 2.2µF 16V    
C6 10µF 16V DS1,DS3 Display 7 Seg. Comm. Cath.
C7 .01µF 63V Mylar S1 ON-OFF mini switch
C8 .001µF 63V Mylar S2 1X2 mini switch
C9 1µF 16V   9V Battery

 


I found two conflicting datasheets on this. One says it’s a microcontroller (which I doubt); the other says it’s a flip-flop. I've looked at Mouser and Digi-Key and can't find this IC, even at some surplus places I've looked!


Can you help?

#1151
Ted Mieske
CA, USA



Answers

By using the resistance and capacitance values for the IC5A 556 timer IC we get one-shot periods between 0.5 and 1.6 seconds for the kHz switch position, and between 0.5 and 1.6 msec in the Hz position. The trimmers would adjust these to 1.00 sec and 1.00 msec respectively. I believe the switch labels (Hz and kHz) in the schematic diagram got swapped. The 1-sec period would let the counters count 0 to 999 pulses (0-1 kHz) and the 1 msec period would open the counters to count from 0 to 999 kHz (0-1 MHz). The calculations eliminate the possibility of IC1 as a prescaler or divide-by-x counter. Thus, IC1 probably is an obsolete CD4583. Don't give up hope: A CMOS Schmitt trigger CD4093 will do the same job, although it requires some rewiring. DigiKey has many in stock for under a dollar.

Jon Titus
Herriman, UT

According to my ancient Motorola CMOS databook, MC14583B is a dual Schmitt trigger in a 16 pin package.  Channels A and B can be used independently or there is an exclusive OR output on pin 14. The outputs are tri-state with the control on pin 13. Pin 13 is not connected which is very, very bad practice. However, channel B input (pin 15) is tied high so only channel A is being used. Therefore, you can use any garden variety Schmitt trigger in its place.

Russell Kincaid
Milford, NH

The 4583 IC in your frequency counter is a non inverting dual Schmidt trigger. I found this in an old Motorola CMOS data book from 1991 #Q4/91 DL131 REV 3 on page 6-498. The Motorola part number is actually MC14583B. Only the A Schmidt is used in your circuit, the B Schmidt is unused. The Schmidt trigger is used in front of the counter IC1 to ensure a clean input to the counter. Typically the Schmidt trigger output will transition low when the input drops below 40% of the supply voltage and the output will go high when the input goes above 60% of the supply voltage. For the MC14583B device these thresholds are adjustable via external resistors through the positive, negative and common terminals. In your circuit those three pins 5, 6 and 7 are bussed together without a resistor and this sets the thresholds to around 40% and 60% of the supply voltage.


Pin 9 is the A input
Pin 4 is the A output
Pin 15 is the B input (unused so tied high to 9V)
Pin 10 is the B output (unused)
Pin 5 is the negative A (pins 5,6 & 7 are tied together to set the A device threshold)
Pin 6 is the positive A
Pin 7 is the common A
Pins 1, 2 and 3 are common, positive and negative for the B Schmidt (unused)
Pin 16 is VDD. Supply voltage, 18volt max for this device
Pin 8 is VSS. Supply voltage return.


A replacement for the '4583' could be the MC14093B or CD4093 available from Newark, etc., although these do not have adjustable thresholds they will be close to those of the 4583. These are quad two input NAND Schmidt triggers, so all unused input pins must be tied high (to 9V in your case).

Roger Baker
Redmond, WA

I found an MC14583B IC in a 1991 Motorola Data Book. This part is a dual Schmidt trigger IC and appears to match the pinout  shown in the schematic. The pinout is not fully legible in the electronic issue. Using a Schmidt trigger in this application makes sense. I have attached a photo of the data sheet.


If IC1 is indeed an MC14583B or equivalent it should not be powered from 9V! The logic high output from Q1 is only 5V. The data sheet for the MC14583B indicates the minimum input voltage required to guarantee a logic high to be 80% of it's supply voltage. Also the logic high output voltage from IC1 is too high for the 5V downstream logic.


It is possible that IC1 is not actually defective but is not seeing a logic high due to poor design. This theory can be tested by substituting a 7 volt power supply for the battery. If it works at the lower voltage, I would modify the circuit to power IC1 from 5V.


I also question not having a resistor between the junction R1/C1 and the base of Q1 to limit input current to a non destructive level! This might best be accomplished by cutting a 1/16" gap in the track leading to the base of Q1 and soldering a 1K surface mount resistor across the gap.


Am attaching a ZIP file with 4 scanned pages of the MC14583B data sheet for your information. MC14583B.zip

Dick Pope
Eatonville, WA

The answer to question 11151 is it is an NE556 dual timer.

George Shepard
Los Osos, CA

The chip you are looking for is a CMOS 4583. It is a dual adjustable  schmidtt  trigger. The 556 timer clocks the 4583 like a gate. I checked the usual places and it may be obsolete.

Tom Grabowski
via email

The best match for IC1 that I found is a Dual Schmitt Trigger, TC4583BP or NTE4583B.

Lance Corey
via email

Because most of the other ICs in this circuit are standard 4000-series CMOS parts, that indicates the 4583 at IC1 likely is also. Using that to refine the search, the part is a dual Schmitt trigger buffer.


The unique property of a Schmitt trigger gate is that it provides hysteresis.  When a slow-rising, slow-falling, or noisy analog signal is applied to an ordinary gate, that gate may oscillate and switch several times as the input crosses its switching threshold. But because this Schmitt trigger requires a much higher input voltage to switch high than it does to switch back low, it will clean up its analog input, and its output will switch only a single time.


In this circuit, that behavior is important because the input signal is being used as a clock for the counters.  Without the Schmitt trigger, some input signals might trigger multiple clock pulses per cycle, resulting in wildly incorrect frequency numbers.


Searching for Motorola's specific version number of this part, MC14583BCP, seems to produce better search results, revealing data sheets and even a seller of the part on Amazon!  However, because the circuit does not actually take advantage of the unique programmable hysteresis feature of the 4583 (by just tying pins 5, 6, and 7 together), any other CMOS Schmitt trigger should work just as well, if you can find something cheaper and don't mind slightly modifying the circuit.

Richard Carlson
Fort Collins, CO

This appears to be a dual Schmitt Trigger. I found the NTE4583B data sheet at: www.nteinc.com/specs/4500to4599/pdf/nte4583B.pdf VCC, GND placement is consistent with your Fig 1 schematic. Pin 9 is "A In" and Pin 4 is "A Out". So this would appear to be a Schmitt Trigger used to clean up the input signal.

D. Ferguson
Austin, TX

The 4583, in that design, is an obsolete dual Schmidt trigger chip, which is intended to square up the input signal so it meets the minimum rise/fall time requirements of the downstream counter chips. Probably the simplest substitution would be a 4584 / 74C14 hex Schmidt trigger chip, with two of its inverters wired in series. The remaining four inverters should have their inputs grounded, to prevent excessive current consumption.

Mike Hardwick
Turner, OR

The chip you asked about the CD4583 is what is known as a Dual Schmitt Trigger ... that chip has been discontinued but some stores still have the NTE4583B which was their substitute for it. I have attached a .pdf file of the NTE Data Sheet for this chip. Worst case is you would need to rewire the schematic to use a more current version of an equivalent chip. nte4583B.pdf


One such store that says they have them is listed below:

www.moyerelectronics.com/BVModules/ProductTemplates/MoyerProductTemp/Product.aspx?productid=1e4bffa7-6961-4e1a-82f7-8a161ab401ea

Bruce Bubello
via email

Try looking at a MC14583B dual schmitt triger with only one side used. Pin out looks correct, Pin 9 is input and Pin 4 is output. Pins 5, 6, 7 are used to adjust hysteresis.

Don Horne
Markdale, ON

Cliff Harris
Anaheim, CA

According to all my old data books, the 4583 IC is a Dual Schmitt Trigger, and NTE supplied them to the service industry, part number NTE4583. You can look at their data sheet here:
www.nteinc.com/specs/4500to4599/pdf/nte4583B.pdf


Supposedly, a company called "Mountain States Electronics has one in stock. Here is their address and contact info:
2107 South College Avenue
Fort Collins, CO 80526


Since the inventory for Mountain States showed only 1 in stock, here is another supplier of the TC4583 Schmitt Trigger chip. These people have a bunch of them and the price is definitely right:
http://store.americanmicrosemiconductor.com/tc4583bp.html

Kevin Kaas
via email


Battery Dilemmanator Answered February 2015

About three years ago, I put together a 1.5 volt battery eliminator using a wall wart feeding into an LM4120 regulator. My goal was to power the clocks I have around the house and save myself the aggravation of replacing the batteries all the time. The clock that I started with is a Howard Miller mantle clock that a company awarded to me for busting my ass for 25 years.


After installing the eliminator, I set the clock to the time of my crack atomic wristwatch and let'er go. The clock ran for almost three years with phenomenal accuracy, matching my watch within a few seconds (a hex on those who disbelieve this). The clock finally died — probably from exhaustion — having gotten no rest between battery exchanges.
Well, I thought, what are you waiting for. Get with it with the other cheap clocks cluttering up our house; so, I did. To my amazement, none of the clocks running on the eliminator could keep time anywhere near what could be termed accurate — no matter how much I adjusted the voltage (usually, the clocks ran fast).


So, what gives? Why does a battery work and my eliminator won't? Some wizard out there must know what the problem is, and be willing to share the knowledge with me.

#2152
Joe Graf
via email



Answers

The LM4120 regulator only puts out a few mA, and this 1.5V application is at the bottom end of the part's voltage range specs. When connected to clocks that need a bit more juice, the regulator sags and puts noise on the DC supply, and that screws up the time keeping.  Solution: Look for a beefier LDO, ensure the wall wart is putting out clean DC when loaded by the clock, and ensure the LDO's input voltage is sufficiently higher that the 1.5V LDO output.

Craig Hyatt
Salt Lake City, UT

I recommend looking at the LM4120 output with a DC coupled oscilloscope and checking for noise or voltage drift, either short-term or long-term. I think you will see the problem.

John Keller
via email

I used battery clocks in an amp hour counter device and found my clocks running slow, sometimes stopping. Maybe your problem is related to mine. It seems that the pulse current to run the ticking solenoid is relatively high. Adding a 100µf electrolytic plus a 1µf ceramic cap directly on my fake battery (wooden dowel with screws on the ends) fixed the problem.

Otmar
Corvallis, OR

First off, I suggest doing the following:


   1. Measure the OPEN-CIRCUIT output of your eliminator before connecting it to the clock you want to run.
   2. Connect the eliminator to the clock, then measure the voltage output again.


If the difference between the "no-load" voltage and "load" voltage is more than 0.5 VDC, it's entirely possible your wart isn't delivering enough current to properly operate the regulator. In this case, try a similar-voltage wart with higher current output (say, 1.5-2X of your current wart). This may solve the problem as wall wart outputs tend to droop severely once you approach their maximum current capability, resulting in severe output instability, (i.e., the regulator won't "regulate" well), increased ripple, noise on the DC output, and severely shortening the life of the wart (i.e., overheating and such).


If the "no-load/load" voltage difference is negligible (< 0.1 VDC), try adding a filter capacitor, (start with 470 µF electrolytic — watch the voltage rating of the cap!), paralleled with with a 0.01µF mica or polyester to filter out high-frequency hash that may be on the DC output feeding the clock. This may give you the stability you're looking for as most, if not all, warts are half-wave, unregulated types with very minimal filtering to begin with. Adding more filtering (larger electrolytic) and bypass (small value) caps to the DC output greatly improves their overall stability and cleanliness of the DC output voltage.


Finally, (as you already know), having a regulator between the wart and your device guarantees a rock solid DC source, as long as you don't pull too much current from the wart.

Ken Simmons
Auburn, WA

Without more information, it's difficult to give a definite answer, but here are three possible causes to check:
  1. Is the output voltage correct? Check with a DVM; anything from 1.35 to 1.6 V should be OK for LCD or quartz clocks.
  2. The power supply has excessive AC in the output, e.g., a bad capacitor. Though you could check this with an audio amplifier or oscilloscope, it's easier to just put a 500 microfarad or larger electrolytic cap across the output and see if that fixes the issue.
  3. AC or RF leakage from the power supply, either from the mains or from a nearby radio transmitter, is making its way into the clock. The clock circuitry is very low power, so any AC could flip some flip-flops a few extra times per second. To check this, you could make a Faraday cage (e.g. window screening) around the clock and connect it to one side of the supply. This is to satisfy your intellectual curiosity, though it's probably not a convenient way to run a clock 😉

B. Bresnik
via email


False Readings Answered December 2014

I bought one of those Internet-aware soil moisture devices a few months ago. It worked great at first, but now the electrodes are oxidized and the readings are falsely dry because of the increased resistance. Scrubbing the electrodes with steel wool works for about a week. Any ideas for a permanent solution?

#12145
Harland Foster
Columbus, OH



Answers

This is a common problem in any sensors that deal with moisture (soil moisture sensing or rain detectors or water level meters). Stainless steel probes may work better. I had better luck with non-metallic conductive probes. I use carbon rods from old carbon-zinc batteries. Carbon, most of the time does not react the way metals do and when it does, it does not cause non-conductive oxide layer like metals. If you can find conductive carbon rods, (I hope modern battery cells still have carbon rods) please try them out.

Anoop Hegde
Milpitas, CA

If the sensor is powered with a direct current voltage, you may be out of luck. However, here are some possible 'fixes'.


I read that the phone company, many years ago, had a problem with corrosion and switched from a negative ground to a positive ground, which helped to solve their corrosion problem. If you could insure the system is + grounded, this may help.


I think that most serious outside systems use AC sensors, and if they use DC, employ a positive ground, and are not powered unless a measurement is needed.

Marc Forgey
Seattle, WA


Photomicrographs Answered December 2014

I need photomicrographs of some 3D printed surfaces for a science fair poster. Is there a commercial electron microscope imaging service that you can recommend? I tried my local community college, but they weren't willing to help.

#12143
Fabian Hoffmann
Seattle, WA



Answers

This is in response to the Fabian Hoffmann question about electron micrographs. We perform limited "community service imaging" of the type Fabian describes for school projects. We would need to know the scope of the project (usually just a few micrographs). Do let us know of your interest. www.marshall.edu/mbic/

Mike Norton
via email


Unregulated Power Supply Answered December 2014

I picked up a 9V switching power supply wart from one of the online suppliers that advertise in Nuts & Volts. Unfortunately, it melted two Arduino's before I realized what was happening. Apparently, the no-load voltage on a switching supply can be up to twice the rated voltage — in my case, 18V. Should I add a load resistor to the internal circuit of the wart so there's always a load? Any other suggestions?

#12142
Fritz Sommer
Knoxville, TN



Answers

Fritz, all you need is an appropriate 3-terminal voltage regulator to protect your Arduino boards. I don't know what voltage your board needs, so I suggest integrating an LM317T programmable regulator between the board's power jack and the board. The regulator will take the wall-wart's high voltage and reduce it to what the board requires. To program the regulator, connect it between the wall-wart and your board's DC input using this diagram as a guide:

Wiring isn't too critical (point-to-point), but keep lead lengths as short as practical. Be sure to include the 2 capacitors as they'll help "keep things stable" and prevent unwanted high-frequency oscillations. NOTE: the voltage rating of C2 should be above 24V as it's typically an electrolytic. Variable resistor R2 will let you dial in the output to what your board requires. BE AWARE: Keep the maximum current draw ** BELOW 1 AMP **, use a heat sink on the regulator (a TO-220 type clamp-on will be sufficient) and keep the regulator's input voltage BELOW 35 VDC!


If you don't want to bother with a variable resistor for R2, visit www.reuk.co.uk/LM317-Voltage-Calculator.htm as it has a nice table of standard resistor values to use for R1 and R2 for programming various output voltages (and other good info on the regulator).

Ken Simmons
Auburn, WA


Nixie Tube Specs Answered December 2014

I have six F-itron DG10A nixie tubes. I need to find specs and pin-outs for these tubes to see if they are okay. Any info is appreciated.

#12141
Alan Moser
Memphis, TN



Answers

According to the information about tne DG10A tube, it isn't a Nixie tube (which uses cold cathode shaped numbers that illuminate orange under a high voltage in the neon gas inside the tube), but a fluorescent glow tube, which uses a multi-segment cathode coated to glow green-blue under a high voltage, like the Nixie. This type of display was used in medium sized calculators and some digital clocks because the emitted light can be filtered, and a version with many digits using a multiplexed circuit was later used in calculators until the LED and LCD displays replaced them I still see calculators with these fluorescent displays. on many desks.


I found an eBay offer for the same type of tube (item #251596633619) that sells the tubes but has posted the wiring diagram for it. Look at the item diagrams to wire up the tube and test it.

Raymond Ramirez
Bayamon, PR

The DG10A is not a nixie tube but is a 7 segment vacuum fluorescent tube. This vacuum fluorescent readout operates much in the fashion of a triode vacuum tube. A heated filament/cathode emits electrons that are attracted to any of the 7 anodes which are biased with a positive voltage. Each anode is coated with a material that fluoresces when the electrons strike the anode. Changing biasing on the control grid varies the intensity of the electron flow and therefore the brightness of the display. The filament requires about 50 milliamperes, which operates just below its incandescent level. About 0.8 VDC will provide the required current. Apply about 50 VDC to each anode (segment) that you want to turn on. For test purposes, the common control grid may also be biased at 50 VDC to provide maximum brightness. The pin-out for the DG10A may be found at www.radiomuseum.org/tubes/tube_dg10a.html

Fred Franke
Kings Park, NY


QuickBASIC Program Answered November 2014

Since you have various articles dedicated to programming PICs in Basic as well as coding for Arduino, I thought that maybe a proficient N&V reader could help me with a sorting program by correctly coding in Microsoft QuickBASIC.


What I'd like to accomplish is by electing choice (1), sort in ascending order just the six-numbered string, paired with the correct and correspoding "date" and "odd/even" strings. Therefore, the six-numbered string is sorted in ascending order while the corresponding date and odd/even string must stay with that six-numbered string (the dates and odd/even strings must also be swapped).


Also, I'd like to print to the screen — bit by bit/segment by segment — the entire generated output by depressing any keyboard button to advance to the next screen segment until I reach the end of the generated sortition. The way I've coded it, it just goes automatically to the last part of the screen output, without being able to ever visualize either the start nor the middle of the generated screen output.


As for choice (2), I’d like to only sort the string dates — in ascending order — paired with the correct six-numbered strings and corresponding odd/even strings. Lastly, I'd like to print to screen (just as for choice 1 — bit by bit) by depressing some button in order to advance to the next screen segment, until the entire generated sortition would have appeared on the screen.


I'm planning to add more data lines in the future, where I'll have to update lines 200 and 390.


Listing 1 below indicates what I'd like. I learned QuickBASIC in the early ‘80s. My coding partially works, but I can't remember how to correctly do everything at my seasoned age of 56.


1 CLS
192 REM:
*******************************************************************
193 REM: (1) SORT IN ASCENDING ORDER: ALL ACTUAL NUMBERS DRAWN (and the corresponding 'dates drawn')
194 REM: (2) SORT IN ASCENDING ORDER: DATES DRAWN (and the corresponding 'numbers drawn')
195 REM: *******************************************************************
196 REM: C$ = RATIO OF EVEN/ODD NUMBERS CONTAINED
197 REM: B$ = ACTUAL NUMBER DRAWN
198 REM: N$ = DATE DRAWN
199 REM: *******************************************************************
200 DIM N$(200), B$(200), C$(200)
201 REM: *******************************
210 REM - READ number of records
211 REM: *******************************
220 READ K
221 REM: **********************************
230 REM - READ records into ARRAYS
231 REM: **********************************
240 FOR I = 1 TO K
250 READ N$(I), B$(I), C$(I)
255 NEXT I
260 PRINT "****************************************************************"
261 PRINT "SORT based on ALL ACTUAL NUMBERS DRAWN by ENTERing (1) OR "
262 PRINT "SORT based on DATES DRAWN by ENTERing (2) ";
263 INPUT C
264 IF C <> 1 AND C <> 2 THEN PRINT "---- < OOPS!.WRONG CHOICE ENTERED!.TRY AGAIN!. ENTER either (1) or (2)!. >----": GOTO 260
265 IF C = 1 THEN 270
266 IF C = 2 THEN 345
267 REM: *******************************************************************
268 REM : SORT based on ALL ACTUAL NUMBERS DRAWN by ENTERing (1)
269 REM: *******************************************************************
270 FOR I = 1 TO K
280 FOR J = 1 TO K - 1
290 IF B$(J) > B$(J + 1) THEN SWAP B$(J), B$(J + 1)
300 NEXT J
310 NEXT I
311 D$ = N$(I) + " , " +B$(I) + ", " + C$(I)
320 REM - sorted in ascending order: ACTUAL NUMBERS DRAWN (with corresponding 'dates drawn') to be printed
330 FOR I = 1 TO K
335 PRINT I, D$
339 NEXT I
340 GOTO 390
342 REM: *******************************************************************
343 REM: SORT based on DATES DRAWN by entering (2)
344 REM: *******************************************************************
345 FOR I = 1 TO K
346 FOR J = 1 TO K - 1
347 IF N$(J) > N$(J + 1) THEN SWAP N$(J), N$(J + 1)
348 NEXT J
349 NEXT I
350 REM - sorted in ascending order: DATES DRAWN (with corresponding 'numbers drawn') to be printed
355 FOR I = 1 TO K
360 PRINT I, N$(I), B$(I), C$(I)
365 NEXT I
390 DATA 200
10001 DATA "10/22/1994", "10,16,20,28,39,40", "(5Even/1Odd)"
10002 DATA "12/10/1994", "21,23,35,37,39,48", "(1Even/5Odd)"
10003 DATA "01/07/1995", "24,31,33,35,40,44", "(3Even/3Odd)"
10004 DATA "02/04/1995", "11,20,21,24,29,42", "(3Even/3Odd)"
10005 DATA "02/11/1995", "14,17,25,30,31,34", "(3Even/3Odd)"
10006 DATA "05/06/1995", "15,18,23,24,36,48", "(4Even/2Odd)"
10007 DATA "05/20/1995", "11,27,34,35,37,45", "(2Even/4Odd)"
.............................................................
10196 DATA "06/25/2003", "10,16,31,35,38,43", "(3Even/3Odd)"
10197 DATA "06/28/2003", "18,19,26,34,46,47", "(4Even/2Odd)"
10198 DATA "07/02/2003", "20,25,26,36,37,47", "(3Even/3Odd)"
10199 DATA "07/16/2003", "10,16,22,24,26,37", "(5Even/1Odd)"
10200 DATA "08/23/2003", "17,24,26,28,41,44", "(4Even/2Odd)"
40000000 END

#11143
Don Franklin
via email



Answers

Attached is a zip file containing two files in response to Don Franklin’s question regarding a Quick Basic Program he wanted to develop. The code is “Very Well” documented with comments and should not require any additional explanation.

Listing_2.zip

 

'**************************************************************************
'*                     PROGRAM DESCRIPTION                               *
'**************************************************************************
'Program asks for the PATHNAME of the DATAFILE.
'   1.  The PATHNAME can have any name that conforms to the 8+3 character
'       limit of the earlier versions of DOS.
'   2.  The Default PATHNAME is "C:\QB\DATAFILE.TXT"
'   3.  The Datafile can have any number of Records but, they must conform                                                
'       to the following Spec.
'    
'       "mm/dd/yyyy", "nn, nn, nn, nn, nn, nn", "(nEVEN/nOdd)" cr-lf
'       | 12 chars |2 |      19 Chars        | 2|  14 Chars  |  2  |
'
'       for a total of 51 characters per record.
'
'The program opens the DATAFILE, determines how many records it contains
'   and loads them into an array of special TYPE "Records"
'While loading the data, the order of elements in the DATE are re-arranged
'       mm/dd/yyyy to yyyy/mm/dd
'
'The program then asks the user to input a 1, 2 or 3 as defined below.
'
'   (1) SORT IN ASCENDING ORDER: ALL ACTUAL NUMBERS DRAWN
'       (and the corresponding 'dates drawn')
'   (2) SORT IN ASCENDING ORDER: DATES DRAWN
'       (and the corresponding 'numbers drawn')+
'   (3) EXIT PROGRAM
'
'The program then prints 20 Data Records at a time waiting for the user
'   to hit any key to move on the the next screen.
'
' AllData()N = DATE DRAWN
' AllData()B = ACTUAL NUMBERS DRAWN
' AllData()C = RATIO OF EVEN/ODD NUMBERS CONTAINED
'
' Edited by Raymond Perry
' [email protected]
'**************************************************************************
'
'**************************************************************************
'*        DESCRIBE a MULTI DIMENSIONAL ARRAY TO HOLD THE DATA             *
'**************************************************************************
'
TYPE Records
    N AS STRING * 12
    Spcr1 AS STRING * 2
    B AS STRING * 19
    Spcr2 AS STRING * 2
    C AS STRING * 14
    CRLF AS STRING * 2
END TYPE
'
'**************************************************************************
'*        Designate the AllData() array to be re-dimensionable            *
'**************************************************************************
'
'$DYNAMIC AllData() AS Records
'
'**************************************************************************
'*               [DIMENSION other variables]                              *
'**************************************************************************
'
DEFINT A-Z
DIM IK AS STRING, TEMP  AS STRING
DIM Pathname AS STRING
'
'**************************************************************************
'*                     PROGRAM STARTS HERE                                *
'**************************************************************************
'
CLS
'
'**************************************************************************
'*                     PROGRAM STARTS HERE                                *
'**************************************************************************
'
'
'**************************************************************************
'*            Get the FileSpec of the File containing the DATA            *
'**************************************************************************
'
PRINT "Enter the complete PATHNAME of the file containing the data."
PRINT "EXAMPLE: C:\QB\DATAFILE.TXT"
INPUT Pathname
'
'**************************************************************************
'*            Use Default FileSpec if input is null                       *
'**************************************************************************
'
IF Pathname = "" THEN
    Pathname = "C:\qb\datafile.txt"
END IF
'
'**************************************************************************
'*            OPEN the File containing the DATA                           *
'*            BINARY access simplifies GETTING DATA                       *
'**************************************************************************
'
OPEN Pathname FOR BINARY AS #1
'
'**************************************************************************
'*            There are 51 characters in each record                      *
'*            There are K Records in the DATA FILE                        *
'**************************************************************************
'
K = LOF(1) / 51
'
'**************************************************************************
'*         REDIMENSION AllData() Array to make room for K elements.       *
'**************************************************************************
'
REDIM AllData(K) AS Records
'
'**************************************************************************
'*         GET the DATA RECORDS and hold them in the AllData(K) array     *
'*         Re-arrange the .N element to YYYY\MM\DD                        *
'**************************************************************************
'
FOR I = 1 TO K
    GET #1, , AllData(I)
    TEMP = CHR$(34) + MID$(AllData(I).N, 8, 4) + "/"
    AllData(I).N = TEMP + MID$(AllData(I).N, 2, 5) + CHR$(34)
NEXT
'
'**************************************************************************
'*         GET the User input to determine sort method or exit prog       *
'*         This is a "DO Forever" loop until the user enters "3" to exit  *
'**************************************************************************
'
DO
    CLS
    PRINT "Enter 1 to sort by NUMBER."
    PRINT "Enter 2 to sort by DATE."
    PRINT "Enter 3 to EXIT the program"
    IK = ""
    '**** Loop Here until user Enters 1, 2 or 3  **************************
    DO WHILE (IK <> "1") AND (IK <> "2") AND (IK <> "3")
        IK = ""
        IK = INKEY$
    LOOP
'
    IF IK = "3" THEN END
'
'**************************************************************************
'*         Continue if user entered a 1 or a 2                            *
'*         Swapping AllData(J) keeps all elements together                *
'**************************************************************************
'
    IF IK = "1" THEN ' SORT BASED ON NUMBERS DRAWN
        FOR I = 1 TO K - 1
            FOR J = 1 TO K - I
                IF AllData(J).B > AllData(J + 1).B THEN
                    SWAP AllData(J), AllData(J + 1)
                END IF
            NEXT J
        NEXT I
    ELSE        ' SORT BASED ON DATE
        FOR I = 1 TO K - 1
            FOR J = 1 TO K - I
                IF AllData(J).N > AllData(J + 1).N THEN
                    SWAP AllData(J), AllData(J + 1)
                END IF
            NEXT J
        NEXT I
    END IF
'
'**************************************************************************
'*         It is time to Print                                            *
'*         Swapping AllData(J) keeps all elements together                *
'**************************************************************************
'
' *********************[ TIME TO PRINT 20 lines ]**************************
    CLS
    FOR Z = 0 TO INT(K / 20) 'THIS CAUSES MULTIPLE PAGES TO PRINT
        FOR I = 1 TO 20  ' THIS LIMITS TO 20 ITEMS PER SCREEN
            IF (Z * 20 + I) <= K THEN
                Y = I + Z * 20
                PRINT Y, AllData(Y).N; AllData(Y).Spcr1; AllData(Y).B;
                PRINT AllData(Y).Spcr2; AllData(Y).C ' ALLDATA(Y).CRLF;
            ELSE
                EXIT FOR
            END IF
        NEXT I
' ***************[ BREAK AT 20 AND WAIT FOR ANY KEY ]************
        PRINT
        PRINT "PRESS ANY KEY TO PRINT THE NEXT SCREEN."
        IK$ = ""
        DO WHILE IK$ = ""
            IK$ = INKEY$
        LOOP
        CLS
    NEXT
LOOP
'
END

 

DATAFILE.TXT

"10/22/1994", "10,16,20,28,39,40", "(5Even/1Odd)"
"12/10/1994", "21,23,35,37,39,48", "(1Even/5Odd)"
"01/07/1995", "24,31,33,35,40,44", "(3Even/3Odd)"
"02/04/1995", "11,20,21,24,29,42", "(3Even/3Odd)"
"02/11/1995", "14,17,25,30,31,34", "(3Even/3Odd)"
"05/06/1995", "15,18,23,24,36,48", "(4Even/2Odd)"
"05/20/1995", "11,27,34,35,37,45", "(2Even/4Odd)"
"06/25/2003", "10,16,31,35,38,43", "(3Even/3Odd)"
"06/28/2003", "18,19,26,34,46,47", "(4Even/2Odd)"
"07/02/2003", "20,25,26,36,37,47", "(3Even/3Odd)"
"07/16/2003", "10,16,22,24,26,37", "(5Even/1Odd)"
"08/23/2003", "17,24,26,28,41,44", "(4Even/2Odd)"
"06/25/2004", "11,16,31,35,38,43", "(3Even/3Odd)"
"06/28/2004", "12,19,26,34,46,47", "(4Even/2Odd)"
"07/02/2004", "24,25,26,36,37,47", "(3Even/3Odd)"
"07/16/2004", "15,16,22,24,26,37", "(5Even/1Odd)"
"08/23/2004", "17,24,26,28,41,44", "(4Even/2Odd)"
"06/25/2005", "15,16,31,35,38,43", "(3Even/3Odd)"
"06/28/2005", "12,19,26,34,46,47", "(4Even/2Odd)"
"07/02/2005", "24,25,26,36,37,47", "(3Even/3Odd)"
"07/16/2005", "14,16,22,24,26,37", "(5Even/1Odd)"
"08/23/2005", "20,24,26,28,41,44", "(4Even/2Odd)"
"06/25/2006", "15,16,31,35,38,43", "(3Even/3Odd)"
"06/28/2006", "12,19,26,34,46,47", "(4Even/2Odd)"
"07/02/2007", "24,25,26,36,37,47", "(3Even/3Odd)"
"07/16/2007", "14,16,22,24,26,37", "(5Even/1Odd)"
"08/23/2008", "20,24,26,28,41,44", "(4Even/2Odd)"
"10/22/1994", "10,16,20,28,39,40", "(5Even/1Odd)"
"12/10/1994", "21,23,35,37,39,48", "(1Even/5Odd)"
"01/07/1995", "24,31,33,35,40,44", "(3Even/3Odd)"
"02/04/1995", "11,20,21,24,29,42", "(3Even/3Odd)"
"02/11/1995", "14,17,25,30,31,34", "(3Even/3Odd)"
"05/06/1995", "15,18,23,24,36,48", "(4Even/2Odd)"
"05/20/1995", "11,27,34,35,37,45", "(2Even/4Odd)"
"06/25/2003", "10,16,31,35,38,43", "(3Even/3Odd)"
"06/28/2003", "18,19,26,34,46,47", "(4Even/2Odd)"
"07/02/2003", "20,25,26,36,37,47", "(3Even/3Odd)"
"07/16/2003", "10,16,22,24,26,37", "(5Even/1Odd)"
"08/23/2003", "17,24,26,28,41,44", "(4Even/2Odd)"
"06/25/2004", "11,16,31,35,38,43", "(3Even/3Odd)"
"06/28/2004", "12,19,26,34,46,47", "(4Even/2Odd)"
"07/02/2004", "24,25,26,36,37,47", "(3Even/3Odd)"
"07/16/2004", "15,16,22,24,26,37", "(5Even/1Odd)"
"08/23/2004", "17,24,26,28,41,44", "(4Even/2Odd)"
"06/25/2005", "15,16,31,35,38,43", "(3Even/3Odd)"
"06/28/2005", "12,19,26,34,46,47", "(4Even/2Odd)"
"07/02/2005", "24,25,26,36,37,47", "(3Even/3Odd)"
"07/16/2005", "14,16,22,24,26,37", "(5Even/1Odd)"
"08/23/2005", "20,24,26,28,41,44", "(4Even/2Odd)"
"06/25/2006", "15,16,31,35,38,43", "(3Even/3Odd)"
"06/28/2006", "12,19,26,34,46,47", "(4Even/2Odd)"
"07/02/2007", "24,25,26,36,37,47", "(3Even/3Odd)"
"07/16/2007", "14,16,22,24,26,37", "(5Even/1Odd)"
"08/23/2008", "20,24,26,28,41,44", "(4Even/2Odd)"

Raymond Perry
Jacksonville, FL

I don't have a quick answer for you, but the version of QuickBASIC you are using is quite out of date. Of the BASICs running on micros these days, I don't think any still use line numbers, REM statements and the like. The language is more structured with subroutine and function names. I too cut my teeth on HP educational BASIC from that era, but really don't miss RENUM as a edit feature. Now you compose programs in an editor and download them to a target. Our BASIC which targets various ARM processors can also be run on a PC in emulation mode, so you can start out writing programs there. www.coridium.us/files/setupBASIC.exe

Bruce Eisenhard
Tahoe Vista, CA

Don, I'm not a QuickBASIC user, but what I see is you need matching SWAP statements (just like you say) in 290 & 347 when true, SWAP N$, SWAP B$, SWAP C$ then your arrays should stay in sync.


I'm not sure I follow your screen print requirement, however, the INPUT statement should allow you to both print an output and then wait for the Enter key to be pressed before continuing. Place the statement at the point you want to interupt. One more thing, the loop 330-339 will print the same value for D$ over and over, you want to move 311 to 331.

Doug Arndt
Chicago, Il

Page 19 of 35 pages ‹ First  < 17 18 19 20 21 >  Last ›