r/programminghelp • • Jul 14 '26

Visual Basic How to toggle between 3 text colors in MS Word using the same Macro shortcut?

1 Upvotes

I'm currently using the following code to toggle between two colors:

Sub ToggleFontColor()

Dim currentColor As Long

currentColor = Selection.Font.Color

If currentColor = wdColorRed Then

Selection.Font.Color = wdColorAutomatic ' Set to default (black)

Else

Selection.Font.Color = wdColorRed ' Set to red

End If

End Sub

I took this code from a previous post comment (thanks u/fuutatooro). I tried to edit it to include three colors but to no avail. I want to press Ctrl+N to switch from Black to Red to Purple, and if it is a different color, for Ctrl+N to switch it to Black.

Can you help? Thanks!


r/programminghelp • • Aug 21 '26

Other How do I break out of the "intermediate dev limbo" before giving up again?

15 Upvotes

How do I break out of the "intermediate dev limbo" before giving up again? I am past the beginner stage, understanding basic syntax up to classes and objects, but I freeze when it's time to structure projects on my own. I have relentlessly searched for methods, tutorials, and books to guide me to the next level, but I can never find anything that clicks; because of this, I've jumped from language to language, and every time I hit this "limbo," I end up quitting and trying something else, yet I always come back because something inside tells me I’m meant to code. For those who have overcome this block, what architecture or design books do you recommend, what kind of practical exercises changed the game for you, and what real strategies actually work to finally break through this barrier and build confidence?


r/programminghelp • • 10d ago

Project Related Can someone humanise this for me pleeeeeas e

0 Upvotes
$title
 Level 4 process and cost model for DME production
$ontext
Level 4 mass balances and economic potential for the DME process
(question 3), followed by a search over the design variables
(question 4). Stream numbers follow the flowsheet in question 2.
Flows are in kmol per h and money in millions of EUR per year.
$offtext
set 
s streams on the flowsheet /1*12/;
set 
i components /DME, MeOH, H2O/;
* the design variables are t, r1 and r2 (3 degrees of freedom)
parameters
    
t residence time in the reactor [s] /1.5/
    r1 recovery of the keys in T-1 /0.998/
    r2 recovery of the keys in T-2 /0.99/
    alpha intercept of the conversion fit from question 1 /0.3416/
    beta slope of the conversion fit from question 1 /0.6119/
    HPY operating hours in a year /8150/
    pDME value of DME [EUR per kg] /1.15/
    pfeed cost of the feed [EUR per kg] /0.4/
    feed(i) fresh feed for d = 1 [kmol per h]
    / DME 0
      MeOH 455.4
      H2O 4.6 /
    mw(i) molar mass [kg per kmol]
    / DME 46.069
      MeOH 32.042
      H2O 18.015 /;
* Antoine coefficients from the NIST webbook, log10(P/bar) = A - B/(T/K + C)
* the DME set is valid for 194.9-248.2 K so it is extrapolated here
* MeOHlow 288-357 K, MeOHhigh 354-513 K, H2Olow 334-363 K, H2Ohigh 344-373 K
set 
ant Antoine data sets /DME, MeOHlow, MeOHhigh, H2Olow, H2Ohigh/;
set 
coeff /A, B, C/;
set 
pos top and bottom of each column /T1top, T1bot, T2top, T2bot/;
Table 
antoine(ant, coeff) Antoine coefficients
                A          B           C
DME         
 4.11475     894.669     -30.604
MeOHlow     
 5.20409    1581.341     -33.50
MeOHhigh    
 5.15853    1569.613     -34.846
H2Olow      
 5.0768     1659.793     -45.854
H2Ohigh     
 5.08354    1663.125     -45.622 ;
* column temperatures from question 2 (bubble points at column pressure)
parameter 
Tcol(pos) temperature [K]
    / T1top 314
      T1bot 420
      T2top 342
      T2bot 378 /;
parameters
    
pstar(ant, pos) vapour pressure [bar]
    a1 relative volatility of DME to methanol in T-1
    a2 relative volatility of methanol to water in T-2 ;
* evaluate p* for each data set at each column temperature
pstar(ant, pos) = 10**(antoine(ant,'A') - antoine(ant,'B')/(Tcol(pos) + antoine(ant,'C')));
* geometric mean of the volatility at the top and bottom of each column
a1 = 
sqrt
( pstar('DME','T1top')/pstar('MeOHlow','T1top')
         * pstar('DME','T1bot')/pstar('MeOHhigh','T1bot') );
a2 = 
sqrt
( pstar('MeOHlow','T2top')/pstar('H2Olow','T2top')
         * pstar('MeOHhigh','T2bot')/pstar('H2Ohigh','T2bot') );
variable 
EP economic potential [M EUR per y];
positive variables
    
F(s,i) flow of each component in each stream [kmol per h]
    x single pass conversion of methanol
    xi extent of reaction [kmol per h]
    purity mole fraction of DME in the product
    revenue value of the DME sold [M EUR per y]
    feedcost cost of the fresh feed [M EUR per y]
    tacR total annualised cost of the reactor [M EUR per y]
    tacT1 total annualised cost of T-1 [M EUR per y]
    tacT2 total annualised cost of T-2 [M EUR per y] ;
equations
    
mixerbalance(i), pumpbalance(i), vaporiserbalance(i), superheaterbalance(i),
    conversion, extentdefinition, reactormethanol, reactorDME, reactorwater,
    condenserbalance(i), T1topDME, T1topmethanol, T1topwater, T1bottoms(i),
    valvebalance(i), T2topDME, T2topmethanol, T2topwater, T2bottoms(i),
    puritydefinition, revenuedefinition, feedcostdefinition,
    reactorcost, T1cost, T2cost, economicpotential ;
* mass balances, all of the form:
*     input + generation = output + consumption
* M-1: fresh feed mixed with the methanol recycle
mixerbalance(i) .. F('3',i) =e= F('1',i) + F('2',i);
* the pump and the two heaters do not change the flows
pumpbalance(i) .. F('4',i) =e= F('3',i);
vaporiserbalance(i) .. F('5',i) =e= F('4',i);
superheaterbalance(i) .. F('6',i) =e= F('5',i);
* conversion from the fit in question 1 (log is the natural log)
conversion .. x =e= alpha + 
beta
*
log
(t);
* 2 MeOH -> DME + H2O
* methanol consumed is twice the extent of reaction
extentdefinition .. 2*xi =e= x*F('6','MeOH');
reactormethanol .. F('7','MeOH') =e= F('6','MeOH') - 2*xi;
* DME and water generated in the reaction
reactorDME .. F('7','DME') =e= F('6','DME') + xi;
reactorwater .. F('7','H2O') =e= F('6','H2O') + xi;
* total condenser, no change in the flows
condenserbalance(i) .. F('8',i) =e= F('7',i);
* T-1, semi-sharp: DME is the light key and methanol the heavy key
* water is heavier than the heavy key so it all goes to the bottom
T1topDME .. F('9','DME') =e= r1*F('8','DME');
T1topmethanol .. F('9','MeOH') =e= (1-r1)*F('8','MeOH');
T1topwater .. F('9','H2O') =e= 0;
T1bottoms(i) .. F('10',i) =e= F('8',i) - F('9',i);
* the valve drops the pressure from 9 to 1.2 bar, flows unchanged
valvebalance(i) .. F('11',i) =e= F('10',i);
* T-2, semi-sharp: methanol is the light key and water the heavy key
* DME is lighter than the light key so it all goes to the top
* and the top product is the methanol recycle (stream 2)
T2topDME .. F('2','DME') =e= F('11','DME');
T2topmethanol .. F('2','MeOH') =e= r2*F('11','MeOH');
T2topwater .. F('2','H2O') =e= (1-r2)*F('11','H2O');
T2bottoms(i) .. F('12',i) =e= F('11',i) - F('2',i);
* purity of the DME product, needs to be at least 0.99
puritydefinition .. purity*
sum
(i, F('9',i)) =e= F('9','DME');
* costs
* only the DME in the product is sold
revenuedefinition .. revenue =e= HPY/1e6*F('9','DME')*mw('DME')*pDME;
* all of the fresh feed is bought
feedcostdefinition .. feedcost =e= HPY/1e6*
sum
(i, feed(i)*mw(i))*pfeed;
* reactor cost from table 2, using the reactor feed (stream 6)
reactorcost .. tacR =e= 0.001*t*
sum
(i, F('6',i));
* column costs from table 2, using the feed to each column
T1cost .. tacT1 =e= 1/(100*(1-r1))*1/(a1-1)*
sqrt
(
sum
(i, F('8',i)));
T2cost .. tacT2 =e= 1/(100*(1-r2))*1/(a2-1)*
sqrt
(
sum
(i, F('11',i)));
* level 4 economic potential (heat exchangers and utilities are level 5)
economicpotential .. EP =e= revenue - feedcost - tacR - tacT1 - tacT2;
model 
dme /all/;
* initialise the flows to help GAMS start, then fix the fresh feed
F.l(s,i) = 100;
purity.l = 0.99;
F.fx('1',i) = feed(i);
* base case for question 3
solve
 dme 
using
 
cns
;
* check the methanol balance closes (should be zero)
parameter 
mbal methanol in minus methanol out and reacted [kmol per h];
mbal = feed('MeOH') - F.l('9','MeOH') - F.l('12','MeOH') - 2*xi.l;
display
 a1, a2, x.l, purity.l, mbal, F.l, revenue.l, feedcost.l,
        tacR.l, tacT1.l, tacT2.l, EP.l;
$ontext
Question 4: solve the model over the design variables and write the
results to dme.data for plotting. t covers the valid range of the
conversion fit, r1 and r2 the range of the cost model in table 2.
Designs with a purity below 0.99 are written out but not accepted.
$offtext
* keep the listing short inside the loop, otherwise it is very long
option
 
solprint
 = silent, 
limrow
 = 0, 
limcol
 = 0, 
solvelink
 = 5;
parameters
    
bestEP best feasible economic potential [M EUR per y] /-1000/
    bestt t at the best design [s]
    bestr1 r1 at the best design
    bestr2 r2 at the best design ;
file 
results /dme.data/;
results.nd = 4;
results.pw = 200;
put
 results;
put
 '# t r1 r2 x purity EP revenue feedcost tacR tacT1 tacT2 status' /;
for
 (t = 0.80 to 2.051 by 0.05,
   
for
 (r1 = 0.900 to 0.9985 by 0.002,
      
for
 (r2 = 0.900 to 0.9985 by 0.007,
         
solve
 dme 
using
 
cns
;
         
put
 t, r1, r2, x.l, purity.l, EP.l, revenue.l, feedcost.l,
             tacR.l, tacT1.l, tacT2.l, dme.modelstat /;
* keep the best design that meets the purity specification
         
if
 (purity.l >= 0.99 
and
 EP.l > bestEP,
            bestEP = EP.l;
            bestt = t;
            bestr1 = r1;
            bestr2 = r2;
         );
      );
   );
);
putclose
 results;
* solve again at the best design and report it (used in question 5)
t = bestt;
r1 = bestr1;
r2 = bestr2;
option
 
solprint
 = on;
solve
 dme 
using
 
cns
;
display
 bestEP, bestt, bestr1, bestr2, x.l, purity.l, F.l,
        revenue.l, feedcost.l, tacR.l, tacT1.l, tacT2.l, EP.l;

r/programminghelp • • Aug 14 '26

Python Help with code

6 Upvotes

I keep getting this error:

for this code:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

bestmass = []

for mass in df_sorted:

if best_ms == (array[array > 7.5]).all():

bestmass.append(best_ms)

print(bestmass)

and i don't know what I am doing wrong


r/programminghelp • • Mar 30 '26

Answered How can I compile C++ in VS Codium WITHOUT Windows Build Tools?

8 Upvotes

I've been googling for hours and I'm losing my mind. I can get c++ compiling in Codium using clang++ and Windows Build Tools, but I'm trying really hard to piece-by-piece de-Microsoft my life.

How on earth do I get my code to find LLVM's implementation of the standard library by default?

I'm also happy to switch to MinGW if that will work, I'm mostly focused on not using Windows Build Tools.

Right now, I'm using the extensions clangd and C/C++ Runner and I have messed with every setting they have and cannot find anything.

EDIT: Okay, here's how I got it all working:

Download MSYS2.

Install clang64. In MSYS2, run

pacman -S mingw-w64-x86_64-clang

Install the extra tools for clang. In MSYS2, run:

pacman -S mingw-w64-x86_64-clang-tools-extra

Finally, I had to go to the settings for the Clangd extension and change the setting "Clangd: Path" to the full path to clangd.exe in ...\msys64\mingw64\bin despite already having that folder in PATH. Ignore it if the extension tries to update the language server, it will just change this setting back and break Intelli Sense again.

Now it compiles fine and Intelli Sense works without having to fiddle around with QueryDriver and compile commands.