Sending string as int params in php - colors

I'm using fpdf library to generate some pdf files with php. At this moment I'm lost, because i can't set the background color.
So, I have to use the SetColor(int r, int g, int b) function and I wish to send the values of RGB as a variable.
Using SetColor($my_color) in which $my_color = "233, 155, 123" is not the right choose.
How can I send a color variable to SetFillColor function?

You could use explode on $my_color and then convert each element to an integer.
$rgb = explode(', ', $my_color);
SetColor(intval($rgb[0]), intval($rgb[1]), intval($rgb[2]))

Related

Convert into const(char)* from float in D

DrawText's first argument needs to be a const(char)* but i tried using to! for that and have failed :(
yVel = to!(string)(player.vel.y);
DrawText(yVel, player.pos.x, player.pos.y - 40, 20, RAYWHITE);
How to properly convert from float to const(char)* ?
to!string converts from float to string. Then toStringz converts from string over to a const char*. So just combine them.
Or for more control and efficiency, you could define a little stack buffer and sprintf or something as well.
Generally some_string.ptr will give something you can use as const char*, just make sure you put the 0 terminator at the end before passing it to most C or Windows functions.

Write Float in File Python3, without Converting it into String

I am trying to use loop to write float into a file, but the write function does not let it happen until I convert it into string or use format, which eventually converts it into string.
Is there any way that I can do it? I need the data inside the file to be in float, since later on the file data can be used to create graphs, thus strings can not be a way out.
Later on I need to use Termgraph Python3 library for this, and the data needs to be a float.
print("sequence","Sign","Values")
f = open("termdata.dat","w")
f.write("Sequence,Score\n")
for i in range(0,len(list_one)):
value1 = list_two[i]
value_ = q_score[value1]
print(list_one[i],"\t", list_two[i],"\t", value_)
str1 = str(list_one[i])
float1 = float(value_)
f.write(str1)
f.write(",")
f.write(str(float1))
f.write("\n")

Fill Excel cells with colors using export method of Acumatica

I'm trying to fill programmatically the cells of Excel with colors using the export method I found about through this post. I've noticed the library contains a method called AddFill with the following parameters AddFill(int startRow, int startColumn, int endRow, int endColumn, string fgColor, string bgColor, [bool doNotOverride = false]) but everything I set as fgColor and/or bgColor makes the cell color go full black. I've tried "red", "Red", "RED", "#FF0000", "(255,0,0)" and its always the same result. It would be very helpful if anyone knows how to do that using the library Acumatica uses to fill the cell with color
There is a utility method PX.Export.Excel.Core.Utils.RgbToColor in Acumatica libraries to convert the value from a .Net Color class integer ARGB value:
AddFill(startRow, startColumn, endRow , endColumn,
PX.Export.Excel.Core.Utils.RgbToColor(System.Drawing.Color.AliceBlue.ToArgb()),
PX.Export.Excel.Core.Utils.RgbToColor(System.Drawing.Color.FromArgb(255, 0, 0).ToArgb()));
The method is public so you should be able to re-use it but in case you have to roll your own here is the implementation:
public static string RgbToColor(int rgb)
{
if (rgb == 0) return "00000000";
return rgb.ToString("x");
}
Basically the expected format can be achieved by calling the ToString method of a integer object with parameter x. I believe this returns an integer value in the form of an hexadecimal string.
More details about this format can be found here:
https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#XFormatString
Hardcoded string '00000000' is a special case with a meaning of 'no color' for Excel.

Xcode 6.1 & Swift - textField input string to integer for basic math

I am slowly understanding things in swift, I am coming for a javascript background so it is somewhat familiar.
However variables are urking me.
in JS a variable can be
var varName = 1; //Number
var varName2 = "petey" //String
var conCat = varname + varName2; // 1petey
however in swift String vars and In var are troubling me. All I want to do is capture decimal number from user input from multiple "textField" sources and store that data to variable (which i already have setup) I need to concatinate a few of them with + then do basic math with the data in the variables with * and /.
How do I make the textFeld only capture?int or how do I convert text field strings to numbers, e.g. int?
A UITextField contains a String, not an Int, so you have to convert it, e.g.
let number : Int? = textField.text.toInt()
So, there actually is a method to convert from String to Int built-in in Swift. Beware, that it returns an optional, because the conversion may fail. So you have to check for nil before you use the variable.
For your other question, take a look at e.g. UITextField - Allow only numbers and punctuation input/keypad. Basically, you will have to adapt UITextField and filter it, once there are new entries. On iOS it might be easier, because you can show a numbers-only keyboard.
The data send from the textField is String. There are multiple ways to convert an Int to a String.
var a:String="\(2+3)" //"5"
And to concatenate a String to Int :
var b:String="Hello "+"\(3*4)" //"Hello 12"
And to Convert a String to an Int from a textField:
var b:Int=textField.text.toInt()
Use the function in swift inputmethod.intValue(); if any text is entered then it returns with a 0.

MFC: Render string in multiple formats

Using a CDC & CDC::DrawText(Ex), I want to render a string with a sub-string in bold
e.g:
void renderText(CDC *pDC,CString &str,int boldStart,int boldEnd)
{
...
}
example: renderText(pDC,"Test
String",0,3) -> Test String
example: renderText(pDC,"Test
String",5,-1) -> Test String
I assume I'll make 3 CDC::DrawText calls, but how do I know the positions to draw each string?
Use CDC::GetTextExtent to get the number of pixels each piece of the string will take up, and adjust the points you pass into CDC::DrawText accordingly.

Resources